Skip to content

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

Description

@johnnian

一、现象

环境: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: andrey.petrov@shazow.net
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低版本的。

四、参考链接

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions