我创建了一个Flask应用程序,其端点可以用于Dropbox webhooks。 Dropbox webhook是一种服务,当我们的Dropbox文件夹中发生某些事件时(如上传文件),它会调用我们定义的API端点。我的应用程序的配置如下图所示,清楚地显示已启用webhook URI,即Dropbox webhook的质询URI正常工作(此处隐藏了API_KEY,API_SECRET和app.secret_key)。
接下来,您可以看到我的烧瓶应用程序的代码。问题是我希望每次将文件上传到我的Dropbox文件夹时都会触发/ webhook POST调用,但它永远不会发生。你知道解决这个问题的正确方法吗?谢谢。
# App key and secret from the App console (dropbox.com/developers/apps)
APP_KEY = "XXXXXXXXXXXXX"
APP_SECRET = "YYYYYYYYYYYYY"
app = Flask(__name__)
app.debug = True
# A random secret used by Flask to encrypt session data cookies
app.secret_key = "zzzzzzzzzzzzz"
def process_user(account):
print("Yeahhhhh")
@app.route('/webhook', methods=['GET'])
def challenge():
'''Respond to the webhook challenge (GET request) by echoing back the challenge parameter.'''
resp = Response(request.args.get('challenge'))
resp.headers['Content-Type'] = 'text/plain'
resp.headers['X-Content-Type-Options'] = 'nosniff'
return resp
@app.route('/webhook', methods=['POST'])
def webhook():
'''Receive a list of changed user IDs from Dropbox and process each.'''
# Make sure this is a valid request from Dropbox
signature = request.headers.get('X-Dropbox-Signature').encode("utf-8")
if not hmac.compare_digest(signature, hmac.new(APP_SECRET, request.data, sha256).hexdigest()):
abort(403)
for account in json.loads(request.data)['list_folder']['accounts']:
threading.Thread(target=process_user, args=(account,)).start()
return ''
if __name__=='__main__':
app.run(host='0.0.0.0')
如果您没有收到来自Dropbox的预期webhook notification请求,有几件事需要检查。确保你有: