requests.exceptions.SSLError: HTTPSConnectionPool(host=‘.*.‘, port=443): 开启代理时无法使用python的requests库

这篇具有很好参考价值的文章主要介绍了requests.exceptions.SSLError: HTTPSConnectionPool(host=‘.*.‘, port=443): 开启代理时无法使用python的requests库。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

requests.exceptions.SSLError: HTTPSConnectionPool(host=‘.*.‘, port=443): 开启代理时无法使用python的requests库,Python人生,ssl,网络协议,网络

python的requests,开启v2rayN后,无法使用python的requests库报错:

Traceback (most recent call last):
  File "E:\Dpandata\Myproject\Sjj1024\venv\lib\site-packages\urllib3\connection.py", line 174, in _new_conn
    conn = connection.create_connection(
  File "E:\Dpandata\Myproject\Sjj1024\venv\lib\site-packages\urllib3\util\connection.py", line 95, in create_connection
    raise err
  File "E:\Dpandata\Myproject\Sjj1024\venv\lib\site-packages\urllib3\util\connection.py", line 85, in create_connection
    sock.connect(sa)
TimeoutError: [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "E:\Dpandata\Myproject\Sjj1024\venv\lib\site-packages\urllib3\connectionpool.py", line 703, in urlopen
    httplib_response = self._make_request(
  File "E:\Dpandata\Myproject\Sjj1024\venv\lib\site-packages\urllib3\connectionpool.py", line 386, in _make_request
    self._validate_conn(conn)
  File "E:\Dpandata\Myproject\Sjj1024\venv\lib\site-packages\urllib3\connectionpool.py", line 1042, in _validate_conn
    conn.connect()
  File "E:\Dpandata\Myproject\Sjj1024\venv\lib\site-packages\urllib3\connection.py", line 358, in connect
    self.sock = conn = self._new_conn()
  File "E:\Dpandata\Myproject\Sjj1024\venv\lib\site-packages\urllib3\connection.py", line 186, in _new_conn
    raise NewConnectionError(
urllib3.exceptions.NewConnectionError: <urllib3.connection.HTTPSConnection object at 0x0000019EDD55E5B0>: Failed to establish a new connection: [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "E:\Dpandata\Myproject\Sjj1024\venv\lib\site-packages\requests\adapters.py", line 489, in send
    resp = conn.urlopen(
  File "E:\Dpandata\Myproject\Sjj1024\venv\lib\site-packages\urllib3\connectionpool.py", line 787, in urlopen
    retries = retries.increment(
  File "E:\Dpandata\Myproject\Sjj1024\venv\lib\site-packages\urllib3\util\retry.py", line 592, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='www.google.com', port=443): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x0000019EDD55E5B0>: Failed to establish a new connection: [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。'))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "E:\Dpandata\Myproject\Sjj1024\src\tasks\test_waiwang.py", line 14, in <module>
    response = requests.request("GET", url, headers=headers, data=payload)
  File "E:\Dpandata\Myproject\Sjj1024\venv\lib\site-packages\requests\api.py", line 59, in request
    return session.request(method=method, url=url, **kwargs)
  File "E:\Dpandata\Myproject\Sjj1024\venv\lib\site-packages\requests\sessions.py", line 587, in request
    resp = self.send(prep, **send_kwargs)
  File "E:\Dpandata\Myproject\Sjj1024\venv\lib\site-packages\requests\sessions.py", line 701, in send
    r = adapter.send(request, **kwargs)
  File "E:\Dpandata\Myproject\Sjj1024\venv\lib\site-packages\requests\adapters.py", line 565, in send
    raise ConnectionError(e, request=request)
requests.exceptions.ConnectionError: HTTPSConnectionPool(host='www.google.com', port=443): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x0000019EDD55E5B0>: Failed to establish a new connection: [WinError 10060] 由于连接方在一段时间后没有正确答复或连接的主机没有反应,连接尝试失败。'))

解决办法引用:开启代理时无法使用python的requests库 · Issue #2065 · 2dust/v2rayN · GitHub

有能力的也可以自己查看解决办法 

requests.exceptions.SSLError: HTTPSConnectionPool(host=‘.*.‘, port=443): 开启代理时无法使用python的requests库,Python人生,ssl,网络协议,网络

我这里总结一下解决办法

如果你的请求不想走v2ray的设置:

设置 -> 参数设置 -> 系统代理设置 -> 下拉选中:socks={ip}:{socks_port}

requests.exceptions.SSLError: HTTPSConnectionPool(host=‘.*.‘, port=443): 开启代理时无法使用python的requests库,Python人生,ssl,网络协议,网络

然后再发送请求:可以看到请求成功发送了 

requests.exceptions.SSLError: HTTPSConnectionPool(host=‘.*.‘, port=443): 开启代理时无法使用python的requests库,Python人生,ssl,网络协议,网络

如果你的请求想走v2ray则设置为:

http=http://{ip}:{http_port};https=http://{ip}:{http_port}

requests.exceptions.SSLError: HTTPSConnectionPool(host=‘.*.‘, port=443): 开启代理时无法使用python的requests库,Python人生,ssl,网络协议,网络

 

或者在python代码里添加proxy配置

先设置 -> 参数设置 -> 系统代理设置 -> 下拉选中:socks={ip}:{socks_port},然后允许来自局域网的连接:requests.exceptions.SSLError: HTTPSConnectionPool(host=‘.*.‘, port=443): 开启代理时无法使用python的requests库,Python人生,ssl,网络协议,网络

 然后设置proxies = {'https': '127.0.0.1:10809'},注意端口,如果你的配置上本地监听端口为10808,则python的proxies里面要端口+1:

import requests

url = "https://www.google.com/"

payload = {}
headers = {
    'Upgrade-Insecure-Requests': '1',
    'User-Agent': 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/109.0.0.0 Safari/537.36',
    'sec-ch-ua': '"Not_A Brand";v="99", "Google Chrome";v="109", "Chromium";v="109"',
    'sec-ch-ua-mobile': '?0',
    'sec-ch-ua-platform': '"macOS"'
}
proxies = {'https': '127.0.0.1:10809'}
response = requests.request("GET", url, headers=headers, data=payload, proxies=proxies)

发送请求之后,就可以了:

requests.exceptions.SSLError: HTTPSConnectionPool(host=‘.*.‘, port=443): 开启代理时无法使用python的requests库,Python人生,ssl,网络协议,网络文章来源地址https://www.toymoban.com/news/detail-669456.html

到了这里,关于requests.exceptions.SSLError: HTTPSConnectionPool(host=‘.*.‘, port=443): 开启代理时无法使用python的requests库的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包 赞助服务器费用

相关文章

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包