我不得不做出了一个Python HTTPS请求,我现在用的请求模块,试图让我的生活更轻松。使用请求模块创建Python HTTPS请求的正确方法?
请求需要有一个标题和3个FORM参数URL编码。这是我在做什么:
header = {'Content-type': 'application/x-www-form-urlencoded', 'Authorization':'Basic ' + encoded_string, 'Connection': 'Keep-Alive', 'Host':'host.host.com'}
payload='grant_type=authorization_code&code=' + request.args['code'] + '&state=' + request.args['state'] + '&redirect_uri=http://xxx.xyz.com/request_listener'
url = 'https://serviceprovider.xxx.com/auth/j_oauth_resolve_access_code'
response = requests.post(url, data=payload, headers=header, verify=False)
当我尝试返回response
的content
或text
,我得到一个空字符串。然而,当我打印的实际response
对象,它说,这是一个<Response [200]>
,但如果这实际上是一个200 OK,然后我张贴过的服务器应该去我指定的REDIRECT_URI,我会得到一个通知那里。
这没有发生,我对此感到困惑。
http://docs.python.org/3/library/urllib.request.html#module-urllib.request –
有些事情可以尝试:使用'curl'手动构建请求,以确保您知道有效请求的内容应该是什么。如果这有效,那么你知道在Python中构建或传递请求的方式存在问题。将“有效载荷”构建为字典而不是字符串。尝试构建准备好的请求,以便在将请求发送到服务器之前检查请求状态。 –