我正在尝试此代码:
import requests
url_token = 'https://accounts.google.com/o/oauth2/token'
params = {
'code': request.values.get('code', '', type=str),
'client_id': app.config['SOCIAL_GOOGLE']['consumer_key'],
'client_secret': app.config['SOCIAL_GOOGLE']['consumer_secret'],
'redirect_uri': urllib.quote_plus("https://example.com/google/code"),
'grant_type': 'authorization_code'
}
out = requests.post(url_token, params=params)
在Flask中使用Python-Request。但我收到错误回复:
ERROR - out={
"error" : "invalid_request",
"error_description" : "Required parameter is missing: grant_type"
}
这是标准的POST请求。任何暗示为什么谷歌没有看到grant_type参数?或者是误导性错误消息?
答案 0 :(得分:0)
params
用于向GET请求中的URL添加查询参数,data
用于将数据传递给POST请求,因此您应该将表单POST参数传递为:
out = requests.post(url_token, data=params)
请参阅以下文档:http://docs.python-requests.org/en/latest/user/quickstart/#more-complicated-post-requests