title: How to fix KeyError in python --> KeyError: 'message'?
body: <p>This error usually should not appear, but recently when I run this, this error appears, and I have no clue how I will fix it.
  Please if Anyone can help me to fix this error on this code below:</p>
  <pre><code>import requests
  import json
  from time import sleep
  
  global OFFSET
  OFFSET = 0
  
  botToken = &quot;&quot;
  
  global requestURL
  global sendURL
  
  requestURL = &quot;http://api.telegram.org/bot&quot; + botToken + &quot;/getUpdates&quot;
  sendURL = &quot;http://api.telegram.org/bot&quot; + botToken + &quot;/sendMessage&quot;
  
  def update (url):
      global OFFSET
  
      try:
          update_raw = requests.get(url + &quot;?offset=&quot; + str(OFFSET))
          update = update_raw.json()
          result = extract_result(update)
  
          if result != False:
              OFFSET = result['update_id'] + 1
              return result
          else:
              return False
  
      except requests.exceptions.ConnectionError:
          pass
  
  def extract_result (dict):
      result_array = dict['result']
  
      if result_array == []:
          return False
      else:
          result_dic = result_array[0]
          return result_dic
  
  def is_callback (dict):
      if 'callback_query' in dict:
          return True
  
  def send_message (chatId, message):
      requests.post(sendURL + &quot;?chat_id=&quot; + str(chatId) + &quot;&amp;text=&quot; + message)
  
  def send_message_button (chatId, message, buttonJSON):
      requests.post(sendURL + &quot;?chat_id=&quot; + str(chatId) + &quot;&amp;reply_markup=&quot; + buttonJSON + &quot;&amp;text=&quot; + message)
      #print (sendURL + &quot;?chat_id=&quot; + str(chatId) + &quot;&amp;reply_markup=&quot; + buttonJSON + &quot;&amp;text=&quot; + message)
  
  while True:
      newmessage = update (requestURL)
  
      if newmessage != False:
  
          if is_callback(newmessage) == True:
              userchatid = newmessage['callback_query']['message']['chat']['id']
              usertext = newmessage['callback_query']['message']['text']
              username = newmessage['callback_query']['message']['chat']['first_name']
              callback_data = newmessage['callback_query']['data']
  
              send_message (userchatid, &quot;Callback from &quot; + callback_data + &quot;, pressed by &quot; + username)
  
          else:
              userchatid = newmessage['message']['chat']['id']
              usertext = newmessage['message']['text']
              username = newmessage['message']['chat']['first_name']
  
              if usertext.lower() == &quot;button&quot;:
                  buttonDict1 = {&quot;text&quot;:&quot;Knopf\n&quot; + &quot;hitest&quot;, &quot;callback_data&quot;:&quot;Knopf&quot;}
                  buttonDict2 = {&quot;text&quot;:&quot;Knopf2&quot;, &quot;callback_data&quot;:&quot;Knopf2&quot;}
                  buttonArr = {&quot;inline_keyboard&quot;:[[buttonDict1, buttonDict2]]}
                  send_message_button (userchatid, &quot;Hi &quot; + username, json.dumps(buttonArr))
              else:
                  send_message(userchatid, &quot;You said: &quot; + usertext)
  
      sleep (1)
  </code></pre>
  <p>This is the error that appears to me after I run this bot</p>
  <p>Line: 67</p>
  <p>userchatid = newmessage['message']['chat']['id']</p>
  <p>KeyError: 'message'</p>