Linux学习36- python3.9出现ImportError: urllib3 v2.0 only supports OpenSSL 1.1.1+

遇到问题

python3.9上安装requests 库,requests包引入了urllib3,而新版本v2.x的urllib3 需要OpenSSL 1.1.1+以上版本

所以就出现了报错

复制代码
  File "/root/python39/lib/python3.9/site-packages/_pytest/assertion/rewrite.py", line 186, in exec_module
    exec(co, module.__dict__)
  File "/root/python39/lib/python3.9/site-packages/pytest_yaml_yoyo/plugin.py", line 6, in <module>
    from requests.adapters import HTTPAdapter
  File "/root/python39/lib/python3.9/site-packages/requests/__init__.py", line 43, in <module>
    import urllib3
  File "/root/python39/lib/python3.9/site-packages/urllib3/__init__.py", line 41, in <module>
    raise ImportError(
ImportError: urllib3 v2 only supports OpenSSL 1.1.1+, currently the 'ssl' module is compiled with 'OpenSSL 1.0.2k-fips  26 Jan 2017'. See: https://github.com/urllib3/urllib3/issues/2168

因为我们通过yum安装的openssl-devel版本是1.0.2k

复制代码
# yum install openssl-devel
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
Package 1:openssl-devel-1.0.2k-26.el7_9.x86_64 already installed and latest version
Nothing to do

解决问题

解决办法有2种:

第一种是降级urllib3版本即可

复制代码
pip3 uninstall urllib3
pip3 install urllib3==1.22

这样也就避免了版本冲突问题

第二种办法是升级OpenSSL 1.1.1+以上版本,此方法稍微复杂一些了

复制代码
wget --no-check-certificate   https://www.openssl.org/source/openssl-1.1.1t.tar.gz
tar -zxvf openssl-1.1.1t.tar.gz
cd openssl-1.1.1t/
./config --prefix=/usr/local/my_openssl
make
make install

安装完成后添加软链接

复制代码
tar -zxf ./my_openssl.tar.gz -C /usr/local

mv /usr/bin/openssl /usr/bin/oldopenssl
ln -s /usr/local/my_openssl/bin/openssl /usr/bin/openssl
ln -s /usr/local/my_openssl/lib/libssl.so.1.1 /usr/lib64/
ln -s /usr/local/my_openssl/lib/libcrypto.so.1.1  /usr/lib64/
相关推荐
80s77731 分钟前
动态代理和静态代理的区别,动态代理怎么提高网络安全性
python
小弥儿1 小时前
GitHub今日热榜 | 2026-09-15:AI 智能体与本地生成工具领跑
学习·开源
susplus2 小时前
【初识ARM】ARM相关基础概念
学习·arm
XiHongShi20162 小时前
键盘大小写指示器(代替键盘灯)
学习·计算机
niucloud-admin2 小时前
JAVA V6 多商户商城 开发文档——job 计划任务开发
java·python·github
小叶肥辉2 小时前
LangChain链和LangGraph图的学习笔记【三】——分别用langchain_openai库和langchain_community库调用大模型
笔记·python·langchain
2401_873479403 小时前
IP属地为什么有时显示外省?用IP查询工具核查动态分配、运营商出口与GeoIP库
python·tcp/ip·ip
斯维赤3 小时前
AI Agent学习之路 | Prompt Engineering(提示词工程)的三板斧核心技巧
人工智能·学习·prompt
陈陈CHENCHEN4 小时前
【Linux】服务器根目录磁盘扩容操作记录
linux·运维·服务器
OKkankan5 小时前
LangChain 能力详解!:输出解析、RAG、向量数据库与 Retriever 检索器
数据结构·python·langchain·ai应用