关于requests.exceptions.ProxyError: HTTPConnectionPool(host=‘125.74.93.60‘, port=8083): Max ret。。。

问题:

在使用代理服务器访问 http://httpbin.org/ip,测试返回IP地址,原python代码:

import requests

url='http://httpbin.org/ip'

headers = {

    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.82 Safari/537.36',

}
proxy={
    'http':'http://125.74.93.60:8083'
    # 'http':'http://202.102.86.228:8080',
    #  'http':'http://111.43.79.98:8085',
    # 'http':'http://39.103.175.42:3128',
    # "http":"http://127.0.0.1:80",
}

response=requests.get(url=url,headers=headers,proxies=proxy)

print(response.text)

看来许多博主request的使用方法,也没问题啊,但是运行起来,报错如下:

requests.exceptions.ProxyError: HTTPConnectionPool(host='125.74.93.60', port=8083): Max retries exceeded with url: http://httpbin.org/ip (Caused by ProxyError('Cannot connect to proxy.', NewConnectionError('<urllib3.connection.HTTPConnection object at 0x0000013231F13088>: Failed to establish a new connection: [WinError 10061] 由于目标计算机积极拒绝,无法连接。')))

解决办法:

headers中加上'Connection' key,值为‘close',就可以了。

headers={'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/98.0.4758.82 Safari/537.36',
'Connection':'close'}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
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、付费专栏及课程。

余额充值