0%

python requests exceptions proxyerror and solution

Guide

error

when r = requests.get(url), error occur:

requests.exceptions.ProxyError: HTTPConnectionPool(host=’127.0.0.1’, port=8888):
Max retries exceeded with url: http://www.baidu.com/ (Caused by ProxyError(‘Cannot
connect to proxy.’, NewConnectionError(‘<urllib3.connection.HTTPConnection object
at 0x7f5611990080>: Failed to establish a new connection: [Errno 111] Connection
refused’)))

solutions

1
2
3
4
5
6
$ env | grep -i proxy 

export http_proxy='127.0.0.1:8888'
export https_proxy='127.0.0.1:8888'
export ftp_proxy=''
export socks_proxy=''

edit ~/.bashrc

1
2
3
4
export http_proxy=''
export https_proxy=''
export ftp_proxy=''
export socks_proxy=''

and run source ~.bashrc

Now OK.

or by code

1
2
proxies = { "http": None, "https": None}
requests.get("http://baidu.com", proxies=proxies)

Reference

History

  • 2019/11/08: created.