【问题标题】:Getting a 406 Not Acceptable from Typeform API only when using python-requests仅在使用 python-requests 时从 Typeform API 获取 406 Not Acceptable
【发布时间】:2020-01-02 18:07:27
【问题描述】:
Typeform“以 JSON 格式查看表单”(例如:https://api.typeform.com/forms/rGVAYs 不需要身份验证)API 端点在通过 python requests 库连接时返回 406 Not Acceptable 错误,但没有其他客户端。
python请求发送的请求头如下:
Accept: */*
Accept-Encoding: gzip, deflate
User-Agent: python-requests/2.21.0
【问题讨论】:
标签:
python-requests
http-status-code-406
typeform
【解决方案1】:
出于某种我不知道的原因,Typeform“以 JSON 形式查看表单”API 端点似乎拒绝来自 python requests 库的请求(仅?),发送 HTTP 错误 406 Not Acceptable
解决方案是添加一个标头指定不同的User-Agent,本质上是在欺骗用户代理
import requests
header = {
"User-Agent": "Mozilla/5.0",
}
resp = requests.get("https://api.typeform.com/forms/rGVAYs", headers=header)
print (resp.content)