GET请求在Postman正常但Python报403错误的问题排查与解决
问题:Python请求ArtStation接口返回403(1020错误),Postman却正常工作?
问题详情
我尝试向https://www.artstation.com/projects/39L94v.json发送GET请求,为Python和Postman配置了完全一致的请求头:
请求头配置
JSON格式:
{ "Accept": "application/json", "Accept-Encoding": "gzip, deflate, br", "Accept-Language": "zh-CN,zh;q=0.9,en;q=0.8,ja;q=0.7", "User-Agent": "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko)", "Host": "www.artstation.com" }
Postman raw格式:
accept:application/json accept-encoding:gzip, deflate, br accept-language:zh-CN,zh;q=0.9,ja;q=0.8,en;q=0.7 user-agent:Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) host:www.artstation.com
Python代码及错误表现
我的Python请求代码:
requests.get(url, headers=headers, proxies={'https': 'http://localhost:10809'})
请求返回<Response [403]>,响应文本显示Access Denied,错误码为1020(表示违反防火墙规则)。尝试添加、修改、移除请求头条目均无法解决问题。
Postman测试结果
使用完全相同的请求头和代理配置,Postman请求正常返回200状态码,控制台日志如下:
GET https://www.artstation.com/projects/qe08KR.json 200 594 ms Proxy href: "http://127.0.0.1:10809/" Request Headers accept: application/json accept-encoding: gzip, deflate, br accept-language: zh-CN,zh;q=0.9,ja;q=0.8,en;q=0.7 user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Host: www.artstation.com Request Body Response Headers ...
更新:问题解决
最终排查发现是Python环境损坏,重新安装Python环境后问题得以解决。
内容的提问来源于stack exchange,提问作者涂智仁
相关产品推荐
相关产品推荐

