我在这里完全描述了这个问题: https ://github.com/python-social-auth/social-core/issues/497
我会在这里复制它。完整的上下文是我在 Django 第三方库 python-social-auth 的 Amazon 后端提供商方面遇到了故障。
(https://python-social-auth.readthedocs.io/en/latest/backends/amazon.html)
然而,具体上下文与核心问题并不真正相关,即亚马逊不会接受标头中没有 User-Agent 的请求。
预期行为
Amazon 的身份验证应该与 Facebook 或 Google 等任何其他后端的工作方式相同。特别是对https://www.amazon.com/ap/user/profile的调用?应该返回响应: https ://github.com/python-social-auth/social-core/blob/master/social_core/backends/amazon.py#L37
实际行为
(甚至超出了 python-social-auth/social-core 的范围)当向https://www.amazon.com/ap/user/profile发送请求时,请求从 python 代码或 cUrl 命令失败,而它们从成功邮递员或网络浏览器。
将“用户代理”添加到 cUrl 或 python 中的标头可解决此问题,这样我就可以请求配置文件数据并获得成功的响应。
重现此问题的步骤是什么?
一旦您从 Amazon 获得了有效的 access_token
您可以尝试使用或不使用“user-Agent”标头:
import requests
url_str= 'https://www.amazon.com/ap/user/profile?access_token=<your-access-token>'
headers = {
'User-Agent': 'Mozilla'
}
response = requests.request("GET", url=url_str, headers=headers)
print(response.text)
还有其他意见吗?
这似乎是亚马逊的一个问题,但谁知道他们是否会解决这个问题。我不确定将这个问题发送到他们身边。