使用 urllib OpenSSL 时遇到的问题及解决

题意:

ImportError: urllib3 v2.0 only supports OpenSSL 1.1.1+, currently the 'ssl' module is compiled with LibreSSL 2.8.3

当前使用的 urllib3 版本(v2.0)仅支持 OpenSSL 1.1.1 或更高版本,但你的 Python 环境中的 ssl 模块却是用 LibreSSL 2.8.3 编译的

问题背景:

After pip install openai, when I try to import openai, it shows this error:

安装了openai库之后尝试导入 openai 时出现的错误:

the 'ssl' module of urllib3 is compile with LibreSSL not OpenSSL

I just followed a tutorial on a project about using API of OpenAI. But when I get to the first step which is the install and import OpenAI, I got stuck. And I tried to find the solution for this error but I found nothing.

我刚刚按照一个关于使用OpenAI API的项目的教程进行操作。但当我进行到第一步,即安装和导入OpenAI时,我遇到了问题。我尝试寻找这个错误的解决方案,但什么也没找到。

Here is the message after I try to import OpenAI: 导入OpenAI后出现的消息

python 复制代码
Python 3.9.6 (default, Mar 10 2023, 20:16:38)
[Clang 14.0.3 (clang-1403.0.22.14.1)] on darwin
Type "help", "copyright", "credits" or "license" for more information.

>>> import openai

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/Users/yule/Library/Python/3.9/lib/python/site-packages/openai/__init__.py", line 19, in <module>
    from openai.api_resources import (
  File "/Users/mic/Library/Python/3.9/lib/python/site-packages/openai/api_resources/__init__.py", line 1, in <module>
    from openai.api_resources.audio import Audio  # noqa: F401
  File "/Users/mic/Library/Python/3.9/lib/python/site-packages/openai/api_resources/audio.py", line 4, in <module>
    from openai import api_requestor, util
  File "/Users/mic/Library/Python/3.9/lib/python/site-packages/openai/api_requestor.py", line 22, in <module>
    import requests
  File "/Users/mic/Library/Python/3.9/lib/python/site-packages/requests/__init__.py", line 43, in <module>
    import urllib3
  File "/Users/mic/Library/Python/3.9/lib/python/site-packages/urllib3/__init__.py", line 38, in <module>
    raise ImportError(
ImportError: urllib3 v2.0 only supports OpenSSL 1.1.1+, currently the 'ssl' module is compiled with LibreSSL 2.8.3. See: https://github.com/urllib3/urllib3/issues/2168

I tried to --upgrade the urllib3, but it is still not working. The result is:

我尝试对urllib3进行升级,但是仍然不起作用。结果是:

python 复制代码
pip3 install --upgrade urllib3
Defaulting to user installation because normal site-packages is not writeable
Requirement already satisfied: urllib3 in ./Library/Python/3.9/lib/python/site-packages (2.0.2)

问题解决:

The reason why the error message mentioned OpenSSL 1.1.1+ and LibreSSL 2.8.3 is that urllib3 v2.0 (the version you've installed) requires OpenSSL 1.1.1+ to work properly, as it relies on some new features of OpenSSL 1.1.1.

错误消息中提到OpenSSL 1.1.1+和LibreSSL 2.8.3的原因是,您已安装的urllib3 v2.0版本需要OpenSSL 1.1.1+才能正常工作,因为它依赖于OpenSSL 1.1.1的一些新功能。LibreSSL虽然与OpenSSL相似,但在某些方面可能不完全兼容,特别是如果它的版本低于OpenSSL 1.1.1,则可能不包含urllib3 v2.0所需的功能。

The issue is that the version of the 'ssl' module that is currently installed in your environment is compiled with LibreSSL 2.8.3, which is not compatible with urllib3 v2.0.

问题是,当前在您的环境中安装的'ssl'模块版本是使用LibreSSL 2.8.3编译的,这与urllib3 v2.0不兼容。

To use urllib3 v2.0, you need an 'ssl' module compiled with OpenSSL 1.1.1 or later, by trying:

为了使用urllib3 v2.0,您需要一个使用OpenSSL 1.1.1或更高版本编译的'ssl'模块。您可以尝试以下方法来解决这个问题:

python 复制代码
brew install [email protected]

Or you could use an older version of urllib3 that is compatible suc. For example urllib3 v1.26.6, which does not have a strict OpenSSL version requirement. You can force the version installing with this command:

或者,可以使用与LibreSSL兼容的旧版本的urllib3。例如,urllib3 v1.26.6就没有严格的OpenSSL版本要求。您可以使用以下命令强制安装特定版本

python 复制代码
pip install urllib3==1.26.6
相关推荐
love530love4 分钟前
家用或办公 Windows 电脑玩人工智能开源项目配备核显的必要性(含 NPU 及显卡类型补充)
人工智能·windows·python·开源·电脑
chilavert3181 小时前
关于Python 实现接口安全防护:限流、熔断降级与认证授权的深度实践
python·网络安全
能来帮帮蒟蒻吗1 小时前
Python -将MP4文件转为GIF图片
开发语言·python·学习·视频
suoxiao7772 小时前
通过anaconda安装jupyter
ide·python·jupyter
百锦再2 小时前
MK米客方德SD NAND:无人机存储的高效解决方案
人工智能·python·django·sqlite·android studio·无人机·数据库开发
PacosonSWJTU2 小时前
python使用matplotlib画图
开发语言·python·matplotlib
伶俐角少儿编程2 小时前
2023年12月中国电子学会青少年软件编程(Python)等级考试试卷(六级)答案 + 解析
python·青少年编程·少儿编程·中国电子学会等级考试·中国电子学会
tangjunjun-owen2 小时前
Milvus 2.4 使用详解:从零构建向量数据库并实现搜索功能(Python 实战)
数据库·python·milvus·rag
CryptoRzz3 小时前
印度尼西亚数据源对接技术指南
开发语言·python·websocket·金融·区块链
戌崂石3 小时前
最优化方法Python计算:有约束优化应用——线性可分问题支持向量机
python·机器学习·支持向量机·最优化方法