【发布时间】:2017-05-12 16:49:32
【问题描述】:
我正在尝试从 thetvdb.com 访问 API v2。不幸的是,我总是收到 403 错误。
这是我所拥有的:
#!/usr/bin/python3
import requests
url = "https://api.thetvdb.com/login"
headers = {'content-type': 'application/json'}
payload = {"apikey":"123","username":"secretusername","userkey":"123"}
post = requests.post(url, data = payload, headers = headers)
print(post.status_code, post.reason)
根据 API 文档,我必须进行身份验证才能获得令牌。但我只是得到 403 Forbidden。
现在我用 curl 试了一下:
curl -X POST --header 'Content-Type: application/json' --header 'Accept:
application/json' -d
{"apikey":"123","username":"secretusername","userkey":"123"}'
'https://api.thetvdb.com/login'
这很完美。谁能解释我错过了什么?这让我发疯了。
我也试过了
post = requests.post(url, data = json.dumps(payload), headers = headers)
同样的错误。
【问题讨论】:
-
尝试用
http://requestb.inURL 替换 url 并执行 python 和 curl request 。然后在浏览器中你可以看到你的请求有什么不同在这里是你可以如何使用https://exotel.in/blog/engineering/debugging-your-exotel-webhooks-more-efficiently-using-requestbin/
标签: python post python-requests