我正在 python 3 中开发一个简单的网络抓取工具,但是当我发送 get 或 post 请求时,响应是 403。在 python 2 中工作正常。我在两个版本中使用相同版本的请求库。我有
也尝试过Verify=False/True
但两个版本的差异仍然存在。
请求= 2.22.0
证书=2019.9.11
from requests import get
url = 'https://www.gamestop.com/'
header = {
'Accept': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8',
'Accept-Encoding': 'gzip, deflate, br',
'Accept-Language': 'en-US,en;q=0.5',
'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; WOW64; rv:56.0) Gecko/20100101 Firefox/56.0',
'DNT': '1',
'Upgrade-Insecure-Requests': '1',
'Connection': 'keep-alive',
'Host': 'www.gamestop.com'
}
res = get(url, headers=header, verify=False).status_code
print(res)
# 403 when using python 3.7.4
# 200 when using python 2.7.16
由@blhsing编辑:
下面的列表根据注释跟踪了哪些特定的 Python 版本可以工作以及哪些版本失败。到目前为止,跨平台的每个特定 Python 版本的成功和失败都是一致的。
请随意使用您自己的结果以及用于生成结果的特定 Python 版本来编辑问题的这一部分。
2.7.14 works (blhsing)
2.7.16 works (repl.it)
3.6.5 works (blhsing)
3.6.8 fails (Reinderien and blhsing)
3.7.3 works (wim and blhsing)
3.7.4 fails (repl.it and blhsing)
3.8.0 fails (OP)
repl.it 上的演示:Python 2.7.16 https://repl.it/@blhsing/DapperLikelyBit and Python 3.7.4 https://repl.it/@blhsing/EarlyMessyApplescript