【问题标题】:Requests and Urllib3 is failing when running api get request. Can't connect to HTTPS URL because the SSL module is not available运行 api get 请求时请求和 Urllib3 失败。无法连接到 HTTPS URL,因为 SSL 模块不可用
【发布时间】:2022-11-10 08:22:34
【问题描述】:

我在 linux 环境中使用 python 3.10.8(RedHat 7.9 Maipo)。 在使用所有库手动安装 python 3.10.8 后,我遇到了这个错误:

> [root@epnm-lab ~]# python3 
> Python 3.10.8 (main, Oct 14 2022, 02:15:05)
> [GCC 4.8.5 20150623 (Red Hat 4.8.5-39)] on linux Type "help",
> "copyright", "credits" or "license" for more information.
> >>> import requests
> >>> username = "xxx"
> >>> password = "yyy"
> >>> ip = "zzz"
> >>> requests.get(f"https://{username}:{password}@{ip}/webacs/api/v4/data/Devices?.full=true",
> verify=False)
> Traceback (most recent call last):   File
> "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py",
> line 692, in urlopen
>     conn = self._get_conn(timeout=pool_timeout)   File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py",
> line 281, in _get_conn
>     return conn or self._new_conn()   File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py",
> line 1011, in _new_conn
>     raise SSLError( urllib3.exceptions.SSLError: Can't connect to HTTPS URL because the SSL module is not available.
> 
> During handling of the above exception, another exception occurred:
> 
> Traceback (most recent call last):   File
> "/usr/local/lib/python3.10/site-packages/requests/adapters.py", line
> 489, in send
>     resp = conn.urlopen(   File "/usr/local/lib/python3.10/site-packages/urllib3/connectionpool.py",
> line 787, in urlopen
>     retries = retries.increment(   File "/usr/local/lib/python3.10/site-packages/urllib3/util/retry.py", line
> 592, in increment
>     raise MaxRetryError(_pool, url, error or ResponseError(cause)) urllib3.exceptions.MaxRetryError:
> HTTPSConnectionPool(host='10.88.242.12', port=443): Max retries
> exces?.full=true (Caused by SSLError("Can't connect to HTTPS URL
> because the SSL module is not available
> 
> During handling of the above exception, another exception occurred:
> 
> Traceback (most recent call last):   File "<stdin>", line 1, in
> <module>   File
> "/usr/local/lib/python3.10/site-packages/requests/api.py", line 73, in
> get
>     return request("get", url, params=params, **kwargs)   File "/usr/local/lib/python3.10/site-packages/requests/api.py", line 59, in
> request
>     return session.request(method=method, url=url, **kwargs)   File "/usr/local/lib/python3.10/site-packages/requests/sessions.py", line
> 587, in request
>     resp = self.send(prep, **send_kwargs)   File "/usr/local/lib/python3.10/site-packages/requests/sessions.py", line
> 701, in send
>     r = adapter.send(request, **kwargs)   File "/usr/local/lib/python3.10/site-packages/requests/adapters.py", line
> 563, in send
>     raise SSLError(e, request=request) requests.exceptions.SSLError: HTTPSConnectionPool(host='10.88.242.12', port=443): Max retries
> exceedefull=true (Caused by SSLError("Can't connect to HTTPS URL
> because the SSL module is not available."))
> >>> [root@epnm-lab ~]#

我在这里的其他帖子中看到过,但没有找到解决方案。我也安装了openssl。

> [root@epnm-lab-02-ha-01 ~]# rpm -qa|grep ^openssl*
> openssl-1.0.2k-21.el7_9.x86_64 
> openssl-libs-1.0.2k-21.el7_9.x86_64

这有什么问题吗?谁能帮我解决这个问题?

【问题讨论】:

  • 也许它还需要 Python 模块pyOpenSSL
  • @furas For pyOpenSSL 只是安装?
  • 在 Linux Mint 上,我只安装了 pyOpenSSLopenssl,但我从 Linux Mint/Ubuntu 的特殊仓库安装了 python3.10。也许它可能需要将一些文件.so 复制到带有urllib 的文件夹中
  • 我将尝试安装 pyOpenSSL。尽快给您反馈。谢谢,我的朋友
  • 我已经安装了pyOpenSSL,但它没有用。还有什么建议吗?

标签: python linux redhat


【解决方案1】:

解决了!

这个错误的解决方法是python 3.10版使用openssl 1.1.1版,而我的服务器使用的是openssl 1.0.2。 python 3.10 上的 openssl 版本 1.0.2 已被弃用。所以你需要安装python 3.9.x,因为这个版本支持openssl 1.0.2。

希望有帮助!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-06-05
    • 2019-08-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2019-03-05
    • 1970-01-01
    • 2020-08-01
    相关资源
    最近更新 更多