首页 > 解决方案 > 带有代理的 Python 请求导致 SSLError WRONG_VERSION_NUMBER

问题描述

我不能在 Python 中使用不同的代理。

我的代码:

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()) 

我得到的错误是:

.
.
.
    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)')))

我执行了pip install requests

我执行了pip uninstall pyopenssl,然后尝试pip install使用旧版本的 pyopenssl 但它没有用。

为什么这不起作用?

标签: pythonsslproxypython-requests

解决方案


问题是由于最新的 urllib3 中的错误而发生的(我在 version 中发现了它1.26.3)。尝试降级到1.23via pip3 install urllib3==1.23,它应该可以解决问题。


推荐阅读