今天在使用Python requests.get的时候老是报错,我也没有找出具体原因,在网上看到一个原因是:
http的连接数超过最大限制,默认的情况下连接是Keep-alive的,所以这就导致了服务器保持了太多连接而不能再新建连接。
我以为是我之前采集某API的时候使用requests.get太多的原因,也有人说可能安装shadowsock后不小心设置了全局代理的原因,反正我使用requests.get的时候老是出现如下的错误:
requests.exceptions.ProxyError: HTTPSConnectionPool(host='www.baidu.com', port=4
43): Max retries exceeded with url: / (Caused by ProxyError('Cannot connect to p
roxy.', NewConnectionError(': Failed to establish a new connection: [
WinError 10061] No connection could be made because the target machine actively
refused it',)))
后来在网上找到的解决方法是在程序中加入如下代码就可以使用了:
1 |
import os |
2 |
os.environ[ 'NO_PROXY' ] = 'stackoverflow.com' |