python requests 的代理错误排查
- 2019-06-19
- 折腾
- 2019-06-23 05:02:58
今天用 pycharm 调试 python 程序,一直报500 Internal Privoxy Error
:
<html>
<head>
<title>500 Internal Privoxy Error</title>
<link rel="shortcut icon" href="http://config.privoxy.org/error-favicon.ico" type="image/x-icon"></head>
<body>
<h1>500 Internal Privoxy Error</h1>
<p>Privoxy encountered an error while processing your request:</p>
<p><b>Could not load template file <code>no-server-data</code> or one of its included components.</b></p>
<p>Please contact your proxy administrator.</p>
<p>If you are the proxy administrator, please put the required file(s)in the <code><i>(confdir)</i>/templates</code> directory. The location of the <code><i>(confdir)</i></code> directory is specified in the main Privoxy <code>config</code> file. (It's typically the Privoxy install directory).</p>
</body>
</html>
我以为是开了代理的原因,将代理关闭,报另一个错:
requests.exceptions.ProxyError: HTTPConnectionPool(host='127.0.0.1', port=1080): Max retries exceeded
是 requests 使用了代理无误了,开始排错。
排错
首先检查了 pycharm 的设置,确定没有设置代理:
然后检查了 Windows 10 的代理设置,也没有开启代理:
查了 requests 包的文档,里面提到环境变量 http_proxy 会有影响:
在终端输入 set http_proxy
,发现确实有设这个环境变量,使用 set http_proxy=
将变量置空,问题还是没解决。
重启电脑,问题依旧。
查了下系统的环境变量,真的有在用户变量里发现 http_proxy
:
删了之后重启 pycharm ,一切正常了。
后记
不知道啥时候加的 http_proxy 这个环境变量到系统设置里,坑了自己一把,就水篇博客吧。