我正在尝试将公共令牌传递到我的服务器(内置于python flask中)。但我不断得到:
BadRequestKeyError: 400 Bad Request: The browser (or proxy) sent a request that this server could not understand.
KeyError: 'public_token'
这是我用jQuery写的前端:
onSuccess: async function(public_token, metadata) {
// 2a. Send the public_token to your app server.
// The onSuccess function is called when the user has successfully
// authenticated and selected an account to use.
await fetch('/get_access_token', {
method: 'POST',
body: JSON.stringify({ public_token: public_token }),
});
},
烧瓶中有问题的函数:
@app.route("/get_access_token", methods=['POST'])
def get_access_token():
global access_token
global item_id
public_token = request.form['public_token']
print(public_token)
exchange_response = \
client.Item.public_token.exchange(public_token)
# Store the access_token and item_id in your database
access_token = exchange_response['access_token']
item_id = exchange_response['item_id']
return jsonify(exchange_response)