根据 httplib 文档中的示例:
>>> import httplib, urllib
>>> params = urllib.urlencode({'@number': 12524, '@type': 'issue', '@action': 'show'})
>>> headers = {"Content-type": "application/x-www-form-urlencoded",
... "Accept": "text/plain"}
>>> conn = httplib.HTTPConnection("bugs.python.org")
>>> conn.request("POST", "", params, headers)
>>> response = conn.getresponse()
>>> print response.status, response.reason
302 Found
>>> data = response.read()
>>> data
'Redirecting to <a href="http://bugs.python.org/issue12524">http://bugs.python.org/issue12524</a>'
>>> conn.close()
我的代码是:
import httplib
import urllib
token = request.POST.get('token')
if token:
params = urllib.urlencode({'apiKey':'[some string]', 'token':token})
connection = httplib.HTTPSConnection('rpxnow.com/api/v2/auth_info')
connection.request('POST', "", params)
response = connection.getresponse()
print response.read()
检查我当地的 vars 产量:
连接:“httplib.HTTPSConnection 实例在 0x8baa4ac” 参数:'token=[some string]&apiKey=[some string]'
(我拨打这个电话的指示是:
使用令牌进行 auth_info API 调用: URL:https://rpxnow.com/api/v2/auth_info 参数:
apiKey [some string] token 你上面提取的token值)
但我收到了主题行中提到的错误。为什么?