我正在用python 3开发一个简单的web scraper,但当我发送get或post请求时,响应是403.在python中,2可以很好地工作.我在两个版本中使用了相同版本的请求库.我有
请求数=2.22.0
certifi=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
Edit by @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上的演示.它:Python 2.7.16和Python 3.7.4