Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python3 Requests依赖报错-ImportError: urllib3 v2.0 only suports Openssl 1.1.1+ #76

Open
johnnian opened this issue Jul 12, 2024 · 0 comments
Labels

Comments

@johnnian
Copy link
Owner

johnnian commented Jul 12, 2024

一、现象

环境:Python 3.7.2
现象:Python文件中引入了requests库,在执行的时候报错如下:

ImportError: urllib3 v2.0 only suports 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

二、解决方法

1、检查 requests 版本:

pip show requests

2、重新安装指定版本的request库

$ pip uninstall requests
$ pip install requests==2.29.0
$ pip show urllib3
Name: urllib3
Version: 1.26.15
Summary: HTTP library with thread-safe connection pooling, file post, and more.
Home-page: https://urllib3.readthedocs.io/
Author: Andrey Petrov
Author-email: [email protected]
License: MIT
Location: /XXX/python3.7/site-packages
Requires: 
Required-by: requests

重新安装完成后,问题解决!

三、原理

1、依赖关系: [requests] --> [urllib3] --> [openssl]

在 Python 3.7.2 下默认安装的requests版本为2.30.0,这个版本依赖 urllib3 的 v2.0版本,根据urllib官网的介绍:

Removed support for OpenSSL versions earlier than 1.1.1 or that don’t have SNI support. When an incompatible OpenSSL version is detected an ImportError is raised (#2168).
删除了对早于 1.1.1 或不支持 SNI 的 OpenSSL 版本的支持。当检测到不兼容的 OpenSSL 版本时,将ImportError引发 ( [#2168](https://github.com/urllib3/urllib3/issues/2168) )。

实际查看,操作系统的OpenSSL版本号:

openssl version
OpenSSL 1.0.2k-fips  26 Jan 2017

2、解决思路:

  • 思路1:升级OpenSSL版本:涉及影响太大
  • 思路2:降低requests库的版本

目前采用思路2:根据github描述,requests==2.29.0版本依赖urllib3的 1.21.1~1.27版本,而urllib3 < v2.0 版本的,是支持openssl低版本的。

四、参考链接

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant