如何解决如何绕过python请求SSL和代理错误?
发送带有身份验证的请求时,我收到一个 requests.exceptions.SSLError 错误,您可以在下面看到。
proxies = { 'https' : "http://user:pass@ip:port/" }
url = "https://httpbin.org/ip"
numberResponse = requests.get(url,proxies=proxies).text
print(numberResponse)
requests.exceptions.SSLError
Traceback (most recent call last):
File "C:\Users\K_Yuk\AppData\Local\Programs\Python\python38\lib\site-packages\urllib3\connectionpool.py",line 696,in urlopen
self._prepare_proxy(conn)
File "C:\Users\K_Yuk\AppData\Local\Programs\Python\python38\lib\site-packages\urllib3\connectionpool.py",line 964,in _prepare_proxy
conn.connect()
File "C:\Users\K_Yuk\AppData\Local\Programs\Python\python38\lib\site-packages\urllib3\connection.py",line 359,in connect
conn = self._connect_tls_proxy(hostname,conn)
File "C:\Users\K_Yuk\AppData\Local\Programs\Python\python38\lib\site-packages\urllib3\connection.py",line 496,in _connect_tls_proxy
return ssl_wrap_socket(
File "C:\Users\K_Yuk\AppData\Local\Programs\Python\python38\lib\site-packages\urllib3\util\ssl_.py",line 428,in ssl_wrap_socket
ssl_sock = _ssl_wrap_socket_impl(
File "C:\Users\K_Yuk\AppData\Local\Programs\Python\python38\lib\site-packages\urllib3\util\ssl_.py",line 472,in _ssl_wrap_socket_impl
return ssl_context.wrap_socket(sock,server_hostname=server_hostname)
File "C:\Users\K_Yuk\AppData\Local\Programs\Python\python38\lib\ssl.py",line 500,in wrap_socket
return self.sslsocket_class._create(
File "C:\Users\K_Yuk\AppData\Local\Programs\Python\python38\lib\ssl.py",line 1040,in _create
self.do_handshake()
File "C:\Users\K_Yuk\AppData\Local\Programs\Python\python38\lib\ssl.py",line 1309,in do_handshake
self._sslobj.do_handshake()
ssl.SSLEOFError: EOF occurred in violation of protocol (_ssl.c:1125)
During handling of the above exception,another exception occurred:
Traceback (most recent call last):
File "C:\Users\K_Yuk\AppData\Local\Programs\Python\python38\lib\site-packages\requests\adapters.py",line 439,in send
resp = conn.urlopen(
File "C:\Users\K_Yuk\AppData\Local\Programs\Python\python38\lib\site-packages\urllib3\connectionpool.py",line 755,in urlopen
retries = retries.increment(
File "C:\Users\K_Yuk\AppData\Local\Programs\Python\python38\lib\site-packages\urllib3\util\retry.py",line 573,in increment
raise MaxRetryError(_pool,url,error or ResponseError(cause))
urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='httpbin.org',port=443): Max retries exceeded with url: /ip (Caused by SSLError(SSLEOFError(8,'EOF occurred in violation of protocol (_ssl.c:1125)')))
During handling of the above exception,another exception occurred:
Traceback (most recent call last):
File "c:/Users/K_Yuk/OneDrive/Desktop/Gmail generator/test.py",line 15,in <module>
numberResponse = requests.get(url,proxies=proxies).text
File "C:\Users\K_Yuk\AppData\Local\Programs\Python\python38\lib\site-packages\requests\api.py",line 76,in get
return request('get',params=params,**kwargs)
File "C:\Users\K_Yuk\AppData\Local\Programs\Python\python38\lib\site-packages\requests\api.py",line 61,in request
return session.request(method=method,url=url,**kwargs)
File "C:\Users\K_Yuk\AppData\Local\Programs\Python\python38\lib\site-packages\requests\sessions.py",line 542,in request
resp = self.send(prep,**send_kwargs)
File "C:\Users\K_Yuk\AppData\Local\Programs\Python\python38\lib\site-packages\requests\sessions.py",line 655,in send
r = adapter.send(request,**kwargs)
File "C:\Users\K_Yuk\AppData\Local\Programs\Python\python38\lib\site-packages\requests\adapters.py",line 514,in send
raise SSLError(e,request=request)
requests.exceptions.SSLError: HTTPSConnectionPool(host='httpbin.org','EOF occurred in violation of protocol (_ssl.c:1125)')))
然后我厌倦了 verify=False 作为 requests.get() 参数之一,但随后得到一个 requests.exceptions.ProxyError 错误,您可以在下面看到:
proxies = { 'https' : "http://user:pass@10.10.1.10:3128/"}
url = "https://httpbin.org/ip"
numberResponse = requests.get(url,proxies=proxies,verify=False).text
print(numberResponse)
requests.exceptions.ProxyError
Traceback (most recent call last):
File "C:\Users\K_Yuk\AppData\Local\Programs\Python\python38\lib\site-packages\urllib3\connectionpool.py",in do_handshake
self._sslobj.do_handshake()
FileNotFoundError: [Errno 2] No such file or directory
During handling of the above exception,port=443): Max retries exceeded with url: /ip (Caused by ProxyError('Cannot connect to proxy.',FileNotFoundError(2,'No such file or directory')))
During handling of the above exception,verify=False).text
File "C:\Users\K_Yuk\AppData\Local\Programs\Python\python38\lib\site-packages\requests\api.py",line 510,in send
raise ProxyError(e,request=request)
requests.exceptions.ProxyError: HTTPSConnectionPool(host='httpbin.org','No such file or directory')))
我厌倦了寻找答案,但似乎没有任何效果。我无法使用代理发送请求 验证。有什么想法吗?
解决方法
问题很可能不是身份验证。不幸的是,您没有提供代理配置的详细信息以及用于代理的 URL。您提供的唯一内容是:
proxies = { 'https' : eampleIpWithAuth }
根据堆栈跟踪中对 _connect_tls_proxy
的引用,eampleIpWithAuth
很可能类似于 https://...
,即您尝试通过 HTTPS 访问代理本身。请注意,通过 HTTPS 访问代理与使用用于 HTTPS 的 HTTP 代理不同。当通过 HTTPS 代理访问 HTTPS URL 时,本质上是对代理进行双重加密:
client --- [HTTPS wrapped inside HTTPS] --- proxy --- [HTTPS] --- server
“普通”HTTP 代理上的 HTTPS URL 只有单一加密,即它看起来(简化)如下:
client --- [HTTPS wrapped inside HTTP] --- proxy --- [HTTPS] --- server
您要使用的代理很可能是纯 HTTP 代理,而不是 HTTPS 代理。这实际上是最常见的情况。
发生错误是因为代理无法使用 TLS 但被 TLS 访问。解决方法是使用 http://proxy
而不是 https://proxy
作为代理地址。请注意,后者在旧版本的 Python 中工作,因为不支持通过 HTTPS 的代理,并且该协议的 https://
值被视为与 http://
相同。
我的脚本在 python 3.9 版本中遇到了类似的问题。 当我尝试从 Web 服务器获取一些数据时,我遇到了类似您的异常:
urllib3.exceptions.MaxRetryError
简单地添加这一行来配置您的请求
import requests
import urllib3
requests.packages.urllib3.util.ssl_.DEFAULT_CIPHERS = 'ALL:@SECLEVEL=1'
希望这能帮助您解决问题
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。