title: Python keeps KeyError: 'message' when fetch data from Messenger Callback - Python/flask
body: <p>I've tried to build a simple bot on Messenger that echoing back whenever we send a message to it.</p>
  
  <p>The message is sent successfully so far but in the log, it keeps displaying error:</p>
  
  <pre><code>message_id = data['entry'][0]['messaging'][0]['message']['mid']
  KeyError: 'message'
  </code></pre>
  
  <p>I have no idea why it happen, this is the logic operations:</p>
  
  <pre><code>import requests
  import traceback
  from flask import request
  
  from ...config.default import VERIFY_TOKEN, ACCESS_TOKEN
  
  ROOT_URL = "https://graph.facebook.com/v2.6/me/messages?access_token="
  
  def reply(user_id, page_id, msg):
      data = {
          "sender": {"id": page_id},
          "recipient": {"id": user_id},
          "message": {"text": msg}
      }
      requests.post(ROOT_URL + ACCESS_TOKEN, json=data)
  
  
  def verification_handler():
      if request.args['hub.verify_token'] == VERIFY_TOKEN:
          return request.args['hub.challenge'], 200
      return "Invalid verification token"
  
  
  def handle_incoming_messages(data):
      try:
          # Get all data from Messenger callback - Text
          recipient_id = data['entry'][0]['messaging'][0]['recipient']['id']
          sender_id = data['entry'][0]['messaging'][0]['sender']['id']
          timestamp = data['entry'][0]['messaging'][0]['timestamp']
  
          message_id = data['entry'][0]['messaging'][0]['message']['mid']
          text = data['entry'][0]['messaging'][0]['message']['text']
  
          reply(sender_id, recipient_id, text)
      except KeyError:
          print(traceback.format_exc())
  
      return ''
  </code></pre>
  
  <p>this is the routes:</p>
  
  <pre><code>from flask import Blueprint, request
  
  from .ops import verification_handler, handle_incoming_messages
  
  
  mod = Blueprint('messenger', __name__)
  
  
  # Route: /messenger/
  @mod.route('/', methods=['GET'])
  def verify():
      """Facebook will GET request to this endpoint for verification."""
      return verification_handler()
  
  
  # Route: /messenger/
  @mod.route('/', methods=['POST'])
  def handle():
      data = request.json
      handle_incoming_messages(data)
  
      return ''
  
  
  # Route: /messenger/hello
  @mod.route('/hello')
  def hello():
      return 'hello there'
  </code></pre>