简体   繁体   English

带有代理的 Python 请求导致 SSLError WRONG_VERSION_NUMBER

[英]Python requests with proxy results in SSLError WRONG_VERSION_NUMBER

I can't use the different proxy in Python.我不能在 Python 中使用不同的代理。

My code:我的代码:

import requests

proxies = {
    "https":'https://154.16.202.22:3128',
    "http":'http://154.16.202.22:3128'
    }

r=requests.get('https://httpbin.org/ip', proxies=proxies)
print(r.json()) 

The error I'm getting is:我得到的错误是:

.
.
.
    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(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1122)')))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
 
  .
  .
  .
requests.exceptions.SSLError: HTTPSConnectionPool(host='httpbin.org', port=443): Max retries exceeded with url: /ip (Caused by SSLError(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1122)')))

I executed pip install requests .我执行了pip install requests

I executed pip uninstall pyopenssl , then tried to pip install an old version of of pyopenssl but it didn't work.我执行了pip uninstall pyopenssl ,然后尝试pip install旧版本的 pyopenssl 但它没有用。

Why is this not working?为什么这不起作用?

Issue happens due to bug in latest urllib3(I've spotted it in version 1.26.3 ).问题是由于最新的 urllib3 中的错误(我在1.26.3版中1.26.3 )。 Try downgrading to 1.23 via pip3 install urllib3==1.23 , it should fix the problem.尝试通过pip3 install urllib3==1.23降级到1.23 ,应该可以解决问题。

The proxy you use simply does not support proxying https:// URLs:您使用的代理根本不支持代理https:// URL:

$ https_proxy=http://154.16.202.22:3128 curl -v https://httpbin.org/ip
*   Trying 154.16.202.22...
* TCP_NODELAY set
* Connected to (nil) (154.16.202.22) port 3128 (#0)
* Establish HTTP proxy tunnel to httpbin.org:443
> CONNECT httpbin.org:443 HTTP/1.1
> Host: httpbin.org:443
> User-Agent: curl/7.52.1
> Proxy-Connection: Keep-Alive
> 
< HTTP/1.1 400 Bad Request

Apart from that the URL for the proxy itself is wrong - it should be http://.. and not https://.. even if you proxy HTTPS traffic.除此之外,代理本身的 URL 是错误的 - 即使您代理 HTTPS 流量,它也应该是http://..而不是https://.. But requests actually ignores the given protocol completely, so this error is not the reason for the problem.但是 requests 实际上完全忽略了给定的协议,所以这个错误不是问题的原因。 But just to demonstrate that it would not work either if the proxy itself got accessed with HTTPS (as the URL suggests):但只是为了证明如果代理本身被 HTTPS 访问(如 URL 所示),它也不会工作:

$ https_proxy=https://154.16.202.22:3128 curl -v https://httpbin.org/ip
*   Trying 154.16.202.22...
* TCP_NODELAY set
* Connected to (nil) (154.16.202.22) port 3128 (#0)
* ALPN, offering http/1.1
* Cipher selection: ALL:!EXPORT:!EXPORT40:!EXPORT56:!aNULL:!LOW:!RC4:@STRENGTH
* TLSv1.2 (OUT), TLS header, Certificate Status (22):
* TLSv1.2 (OUT), TLS handshake, Client hello (1):
* error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol
* Curl_http_done: called premature == 0
* Closing connection 0
curl: (35) error:140770FC:SSL routines:SSL23_GET_SERVER_HELLO:unknown protocol

So the fix here would be to use a different proxy, one which actually supports proxying https:// URLs.因此,此处的解决方法是使用不同的代理,该代理实际上支持代理https:// URL。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 python 请求:(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] 错误的版本号 (_ssl.c:1123)')) - python requests: (SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1123)')) Pip SSLError WRONG_VERSION_NUMBER 在代理下 - Pip SSLError WRONG_VERSION_NUMBER under proxy python elasticsearch elasticsearch.exceptions.SSLError: ConnectionError([SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1056)) - python elasticsearch elasticsearch.exceptions.SSLError: ConnectionError([SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1056)) SSL:PYTHON 请求上的 WRONG_VERSION_NUMBER - SSL: WRONG_VERSION_NUMBER ON PYTHON REQUEST 如何修复错误 ssl.SSLError: [SSL: WRONG_VERSION_NUMBER] 版本号错误? - How to fix the error ssl.SSLError: [SSL: WRONG_VERSION_NUMBER] wrong version number? 如何修复 ssl.SSLError: [SSL: WRONG_VERSION_NUMBER] 错误的版本号 (_ssl.c:1056)? - How to fix ssl.SSLError: [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1056)? Python-Django [SSL:WRONG_VERSION_NUMBER]错误 - Python-Django [SSL: WRONG_VERSION_NUMBER] Error python 3 smtplib 异常:“SSL:WRONG_VERSION_NUMBER”登录到 Outlook - python 3 smtplib exception: 'SSL: WRONG_VERSION_NUMBER' logging in to outlook Python cassandra驱动程序-SSL:WRONG_VERSION_NUMBER - Python cassandra driver - SSL: WRONG_VERSION_NUMBER jupyter SSL:WRONG_VERSION_NUMBER - jupyter SSL: WRONG_VERSION_NUMBER
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM