python - 如何在 python 和 webapp2 中发出 POST 请求

标签 python google-app-engine post webapp2

我正在尝试使用带有 webapp2 的 python 和谷歌应用引擎向 Health Graph API 发出 POST 请求。我已经看到一个示例,其中的操作如下:

payload = {'grant_type': 'authorization_code',
    'code': code,
    'client_id': 'xxxxxxxxxxxxxxxxxxxxxxx',
    'client_secret': 'xxxxxxxxxxxxxxxxxxxxxx',
    'redirect_uri': redirect_uri,}
req = requests.post(API_ACCESS_TOKEN_URL, data=payload)

但我似乎无法使用谷歌应用引擎中的请求模块。有没有简单的方法可以做到这一点?

最佳答案

您需要在 Appengine 上使用 Google 的 URL Fetch 库。试试这个:

payload = {'grant_type': 'authorization_code',
    'code': code,
    'client_id': 'xxxxxxxxxxxxxxxxxxxxxxx',
    'client_secret': 'xxxxxxxxxxxxxxxxxxxxxx',
    'redirect_uri': redirect_uri}
result = urlfetch.fetch(url=API_ACCESS_TOKEN_URL, payload = payload, method=urlfetch.POST)

关于python - 如何在 python 和 webapp2 中发出 POST 请求,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19102927/

相关文章:

Python:如何以两种方式对数字进行排序,然后将数字相减

google-app-engine - GCP 可扩展服务代理在转发请求时遇到错误

javascript - jQuery Ajax 成功回调不触发也不返回错误

javascript - Sencha Touch - 有时 POST,其他人做 GET 请求

python - 如何在Python中使用队列处理线程中的异常?

python - pandas 在 csv 列中读取为 float 并将空单元格设置为 0

unit-testing - App Engine 本地单元测试不同实例 [GO]

r - 发送数据时使用POST下载R中的文件

python - 在 Python 中结束评论

java - 一个应用程序,AppEngine 上的多个域