我正在尝试运行此chatbot sample,但是当我向服务器提交示例更新时,我收到以下错误:
Traceback(最近一次调用最后一次):文件“C:\ Python27 \ lib \ site-packages \ flask \ app.py”,第2309行,在调用中返回self.wsgi_app(environ,start_response)文件“C:\ Python27 \ lib \ site-packages \ flask \ app.py“,第2295行,在wsgi_app response = self.handle_exception(e)文件”C:\ Python27 \ lib \ site-packages \ flask \ app.py“,第1741行,in handle_exception reraise(exc_type,exc_value,tb)文件“C:\ Python27 \ lib \ site-packages \ flask \ app.py”,第2292行,在wsgi_app response = self.full_dispatch_request()文件“C:\ Python27 \ lib \ site-packages \ flask \ app.py“,第1815行,在full_dispatch_request中rv = self.handle_user_exception(e)文件”C:\ Python27 \ lib \ site-packages \ flask \ app.py“,第1718行,在handle_user_exception中重新加载(exc_type,exc_value,tb)>文件“C:\ Python27 \ lib \ site-packages \ flask \ app.py”,第1813行,在full_dispatch_request中rv = self.dispatch_request()文件“C:\ Python27 \ lib \ site -packages \ flask \ app.py“,第1799行,在dispatch_request中返回self.view_functionsrule.endpoint文件”c:\ echo.py“,第30行,在webhook for entry ['messaging']中的messaging_event:KeyError:'messaging'
我尝试过类似this的东西,但不适合我 .
app = Flask(__name__)
PAGE_ACCESS_TOKEN = "XXX"
bot = Bot(PAGE_ACCESS_TOKEN)
@app.route('/', methods=['GET'])
def verify():
# Webhook verification
if request.args.get("hub.mode") == "subscribe" and
request.args.get("hub.challenge"):
print 'get ok'
if not request.args.get("hub.verify_token") == "hello":
return "Verification token mismatch", 403
return request.args["hub.challenge"], 200
return "Hello world", 200
@app.route('/', methods=['POST'])
def webhook():
data = request.get_json()
log(data)
if data['object'] == 'page':
for entry in data['entry']:
for messaging_event in entry['messaging']:
# IDs
sender_id = messaging_event['sender']['id']
recipient_id = messaging_event['recipient']['id']
if messaging_event.get('message'):
# Extracting text message
if 'text' in messaging_event['message']:
messaging_text = messaging_event['message']['text']
else:
messaging_text = 'no text'
# Echo
response = messaging_text
bot.send_text_message(sender_id, response)
return "ok", 200
def log(message):
print(message)
sys.stdout.flush()
if __name__ == "__main__":
app.run(debug = True, port = 80)