我正在尝试从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
现在我尝试使用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)
同样的错误
您必须
explicitly
将payload
转换为json字符串并作为data
传递。看起来您已经这样做了,您也可以尝试将用户代理设置为curl/7.47.1
这个程序看起来像
我认为您需要在python请求中传递Accept头。大概是这样的:
相关问题 更多 >
编程相关推荐