requests 代理设置问题解决方案
程序员文章站
2022-05-08 10:00:07
...
今天在部署的时候,发现我本地是OK的,但是部署到服务器上,requests出现如下报错:
requests.exceptions.ProxyError: HTTPConnectionPool(host=‘xx.xx.xx.xx’, port=808): Max retries exceeded with url: http://xxxxx (Caused by ProxyError(‘Cannot connect to proxy.’, NewConnectionError(’<urllib3.connection.HTTPConnection object at 0x7f6af4708f60>: Failed to establish a new connection: [Errno 111] Connection refused’,)))
后来百度搜了下解决方案,找到了这两篇《让requests不走系统 全局 代理》、《requests中的代理设置》。
于是,在请求中添加了以下代码
proxies = {'http': None, 'https': None}
res = requests.post(xxxxx, proxies=proxies)
这样的话,就可以确保requests不使用系统代理,直连服务器了。
再次部署,问题就解决了!
如果需要手动设置代理,可以这样做:
proxies = {
'http': 'http://10.10.1.10:3128',
'https': 'http://10.10.1.10:1080',
}
requests.get('http://example.org', proxies=proxies)
上一篇: Python接口测试-requests库
推荐阅读
-
requests库爬虫如何设置代理ip
-
用iframe设置代理解决ajax跨域请求问题
-
详解webpack-dev-server 设置反向代理解决跨域问题
-
requests库爬虫如何设置代理ip
-
解决Python requests库编码 socks5代理的问题
-
详解在table设置max-width以及min-width兼容问题和解决方案
-
Vue-cli3本地调试时,设置代理解决跨域问题
-
Ubuntu Server 16.04安装MySQL设置远程访问出现问题的完美解决方案(error:10061)
-
安装gin出现的问题及解决和设置代理报错解决
-
该设备或资源(Web代理)未设置为接受端口“7890“上的连接解决方案