Simple WebHooks Receiver我正在用kloudless学习这个关于webhooks的教程。我下载了ngrok并设置了一个指向本地服务器的URL,然后使用Python -m SimpleHTTPServer 8080
设置了一个服务器。我用ngrok给我的URL运行POST请求,并且能够查看/浏览我的本地目录。我想用这个脚本来验证webhook发送者并启动一个任务。你知道吗
#!/usr/bin/env python
from flask import Flask, request, abort
import hmac
import base64
import hashlib
import threading
app = Flask('demo_app')
APP_ID = ''
API_KEY = ''
@app_route('/webook', methods=['POST']) //FIX. @app_route should be @app.route
def receiver():
# Verify the Request Signature
digest = hmac.new(API_KEY,msg=request.data,digestmod=hashlib.sha256).digest()
sig = base64.b64encode(digest)
if not sig == request.headers.get('X-Kloudless-Signature'):
abort(403)
# Since the request is verified we can actually do something
account_id = request.form.get('account')
if account_id:
threading.Thread(target=process_account, args=(account_id,)).start()
# In order to verify that the endpoint is alive you should always return your application id with a 200 OK response
return APP_ID
if __name__ == 'main':
app.run()
我出错了
@app_route('/webhook ', methods=['POST'])
NameError: name 'app_route' is not defined
我是否指定ngrok使用localhost为@app_route
设置的URL?你知道吗
更新
例如,@app_route
应该保留为/webhook
外部URL应该是https://046f3f46.ngrok.io/webhook
。
现在我想知道为什么在我将这个外部URL添加到当前webhooks下的dev门户之后,它给了我一个不受支持的POST
方法,而应用程序显然支持它。你知道吗
更新
因此PythonSimpleHTTPSever
不支持POST方法。
我发现这个python server确实支持GET和POST方法(应该是这样的),但是我得到了一个405错误代码,这也是一个不受支持的方法。不知道发生了什么,一定是环境中的东西。你知道吗
目前没有回答
相关问题 更多 >
编程相关推荐