使用 pip (TLSV1_ALERT_PROTOCOL_VERSION) 安装 python 包时出错

Error installing python package with pip (TLSV1_ALERT_PROTOCOL_VERSION)

我在 Suse Linux Enterprise 11 SP4 上,我正在尝试使用 pip 安装 python 包,但失败并出现以下错误:

环境:

$ python --version
Python 3.6.6

$ pip --version
pip 10.0.1 from /home/<<user>>/.pyenv/versions/3.6.6/lib/python3.6/site-packages/pip (python 3.6)

命令:

$ pip install sendgrid

错误:

Collecting sendgrid
  Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:841)'),)': /simple/sendgrid/
...
...
  Could not fetch URL https://pypi.org/simple/sendgrid/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/sendgrid/ (Caused by SSLError(SSLError(1, '[SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:841)'),)) - skipping
  Could not find a version that satisfies the requirement sendgrid (from versions: )
No matching distribution found for sendgrid
Could not fetch URL https://pypi.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError(SSLError(1, '[SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:841)'),)) - skipping

我试过 all this solutions 但其中 none 已经在 SLES 上工作了。

有什么想法吗?

提前致谢

您可以通过将 pypi.org 和 files.pythonhosted.org 设置为受信任的主机来忽略 SSL 错误。

pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org <package_name>

或者:

尝试使用软件包的 wheel 安装

我终于开始工作了!

似乎默认安装在 SLES 11 SP4 (libopenssl-devel) 上的 openssl 库已经过时了 (OpenSSL 0.9.8)

要验证这一点,您可以 运行:

$ python -c "import ssl; print(ssl.OPENSSL_VERSION)"
OpenSSL 0.9.8j-fips 07 Jan 2009

诀窍是 卸载 libopenssl-devel安装 libopenssl1-devel 像这样:

重要提示:请注意,系统会要求您选择一个选项,请select 卸载 libopenssl-devel-0。9.x-x.xxx.x.x.x

$ sudo zypper install libopenssl1-devel

Loading repository data...
Reading installed packages...
Resolving package dependencies...

Problem: libopenssl1-devel-1.0.1g-0.58.9.1.x86_64 conflicts with libopenssl-devel < 1.0.1 provided by libopenssl-devel-0.9.8j-0.106.9.1.x86_64
 Solution 1: deinstallation of libopenssl-devel-0.9.8j-0.106.9.1.x86_64
 Solution 2: do not install libopenssl1-devel-1.0.1g-0.58.9.1.x86_64

Choose from above solutions by number or cancel [1/2/c] (c): 1
Resolving dependencies...
Resolving package dependencies...

The following NEW package is going to be installed:
  libopenssl1-devel 

The following package is going to be REMOVED:
  libopenssl-devel 

1 new package to install, 1 to remove.
Overall download size: 3.3 MiB. After the operation, 698.0 KiB will be freed.
Continue? [y/n/? shows all options] (y): 
Retrieving package libopenssl1-devel-1.0.1g-0.58.9.1.x86_64 (1/1), 3.3 MiB (19.6 MiB unpacked)
Retrieving: libopenssl1-devel-1.0.1g-0.58.9.1.x86_64.rpm [done]
Removing libopenssl-devel-0.9.8j-0.106.9.1 [done]
Installing: libopenssl1-devel-1.0.1g-0.58.9.1 [done]

现在继续 recompile/reinstall 你的 python 环境:

$ CFLAGS=-I/usr/include/openssl1 LDFLAGS=-L/usr/lib64 pyenv install 3.6.6

最后确认您的 OpenSSL 版本是新版本并使用 pip:

继续安装您的软件包
$ python -c "import ssl; print(ssl.OPENSSL_VERSION)"
OpenSSL 1.0.1g 7 Apr 2014

$ pip install sendgrid

希望对你有帮助!

请参阅'Security Module in SUSE Linux Enterprise 11'了解更多信息