requests.exceptions.ProxyError: HTTPConnectionPool(host=‘127.0.0.1‘, port=xxxx)

当在Python中使用requests库进行网络请求时,如果启用了代理软件,可能会遇到ProxyError异常。异常信息显示为Max retries exceeded with url,表明无法连接到代理服务器。关闭代理软件后,代码执行正常。为了解决这个问题,可以在代码中设置环境变量NO_PROXY,指定不通过代理访问的特定域名,从而确保代码在代理工具运行时也能正常执行。
摘要由CSDN通过智能技术生成

我在执行代码response = session.post(url, headers=header)时,

出现requests.exceptions.ProxyError: HTTPConnectionPool(host='127.0.0.1', port=7890): Max retries exceeded with url: http://xxxxx (Caused by ProxyError('Cannot connect to proxy.', RemoteDisconnected('Remote end closed connection without response'))) 异常。

我的电脑中装了代理软件,关闭时代码执行正常,开启之后出现异常。

如果你的情况与我类似,可以添加以下代码,在开启代理工具之后仍然能够正常执行:

# 指定某个域名不用代理去处理
os.environ['NO_PROXY'] = '你访问的域名(例:www.baidu.com)'
requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=8097) 是一个网络连接错误的异常。它表示在与特定的主机和端口建立连接时出现问题。具体错误信息是"Max retries exceeded with url: /env/main (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at 0x0000019B93886588>: Failed to establish a new connection: [WinError 10061] No connection could be made because the target machine actively refused it',))"。这个错误通常是因为无法连接到目标主机所导致的。可能的原因包括目标主机处于离线状态,网络连接不稳定,或目标主机主动拒绝了连接请求。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *2* [requests.exceptions.ConnectionError:HTTPSConnectionPool(host](https://blog.csdn.net/a6864657/article/details/94381948)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *3* [visdom安装及启动/requests.exceptions.ConnectionError: HTTPConnectionPool(host=‘localhost‘, port=...](https://blog.csdn.net/qq_42514371/article/details/127838311)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值