环境:mac, iterm2 - zsh
关键词:pycharm, ProxyError, ‘Cannot connect to proxy’, Connection refused, …
先说结论:环境变量搞的鬼
我手头有两个代理
a******(port: 3213) 和 s**********(port: 7000)
开启 pycharm,随便写一个脚本,比如:
import requests
resp = requests.get('https://www.google.com')
print(resp)
都会显示代理拒绝连接,报错信息如下:
requests.exceptions.ProxyError: HTTPSConnectionPool(host='www.google.com', port=443): Max retries exceeded with url: / (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<urllib3.connection.VerifiedHTTPSConnection object at 0x103139fd0>: Failed to establish a new connection: [Errno 61] Connection refused')))
明明已经在 preference -> appearance & behavior -> system settings -> http proxy
中设置了不使用代理,check connection 也没问题,为什么还是走了代理,而且代理还是拒绝连接呢?
答案在跑脚本的地方:看屏幕左下方(命令行左侧)的绿色小三角(run)下面的小扳手(edit run configuration),点进去
找到 Configuration -> Environment -> Environment Variables ,点进去
看,下面的 Include system environment variables
里,这里是把命令行代理(port:7000)也给加上了(好巧不巧我平时都是把7000端口的命令行代理关掉的… 只用3213),所以把 Include system environment variables
前面的方框取消勾选即可
再跑一遍,发现OK啦!
老哥老姐要是解决了问题点个赞啊