无法在Ubuntu 14.04上升级pip 1.5.4-InsecurePlatformWarning:真正的SSLContext对象不可用

时间:2018-11-27 17:52:17

标签: python python-2.7 ssl pip ubuntu-14.04

我目前在Ubuntu 14.04和python 2.7.6上运行pip,版本1.5.4,并且无法将pip升级到最新版本。

当我运行pip install --upgrade pip时,出现以下错误:

Cannot fetch index base URL https://pypi.python.org/simple/ Could not find any downloads that satisfy the requirement pip in ./.venv/lib/python2.7/site-packages Downloading/unpacking pip Cleaning up... No distributions at all found for pip in ./.venv/lib/python2.7/site-packages Storing debug log for failure in /home/buffcat/.pip/pip.log

当我尝试使用get-pip.py升级时,出现以下ssl错误:

/tmp/tmpKVfWOr/pip.zip/pip/_vendor/urllib3/util/ssl_.py:369: SNIMissingWarning: An HTTPS request has been made, but the SNI (Server Name Indication) extension to TLS is not available on this platform. This may cause the server to present an incorrect TLS certificate, which can cause validation failures. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings /tmp/tmpKVfWOr/pip.zip/pip/_vendor/urllib3/util/ssl_.py:160: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. You can upgrade to a newer version of Python to solve this. For more information, see https://urllib3.readthedocs.io/en/latest/advanced-usage.html#ssl-warnings Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '_ssl.c:510: error:14090086:SSL routines:SSL3_GET_SERVER_CERTIFICATE:certificate verify failed'),)': /simple/pip/

我该如何升级机器上的点子?

1 个答案:

答案 0 :(得分:2)

绕过pip升级Ubuntu系统python-pip(由Ubuntu发行版的apt-get debian软件包提供的)是not recommended,这样做是可以接受的在venv / virtualenv中或在您的用户主目录级别(--user pip选项)。这种方式允许使用它而不会与“系统” pip冲突。看来您在virtualenv内部工作,这是一个好习惯。

SSLError是由于以下事实导致的:您的系统的基础OpenSSL库版本<1.0.1和Python版本<2.7.9自大约一年前就不支持PyPI TLS protocol version 1.2的较新expects 。因此pip无法再通过旧版SSL / TLS协议连接到PyPI。
您可以使用以下命令检查版本:
    $ python -c "import ssl; print(ssl.OPENSSL_VERSION)" && openssl version
即使没有点子也可能会重现该错误,例如:
$ curl -i https://pypi.org/simple/ --tlsv1
卷曲:(35)错误:1409442E:SSL例程:SSL3_READ_BYTES:tlsv1警报协议版本

由于pip无法连接到PyPI,我们可以手动对其进行升级:

  • 在Firefox中,打开Python软件包索引official webpage并找到the pip project
  • 在此处选择“下载文件”-这里是直接链接:https://pypi.org/project/pip/#files
  • 点击 wheel 格式( .whl )的最新点子打包文件,下载
  • 在您一直在使用的venv / virtualenv中安装,例如:

        $ source bin/activate
        (venv) $ pip install --no-index ~/Downloads/pip-19.0.1-py2.py3-none-any.whl
        (venv) $ pip --version
         pip 19.0.1 from ...
    

但是升级/安装更新的pip版本是成功的一半。为了使其能够连接到PyPI,我们需要解决根本原因:InsecurePlatformWarning .. Caused by SSLError .. SSL routines:SSL23_GET_SERVER_HELLO:tlsv1 alert protocol version'。 要解决此问题,除了pip之外,您还需要手动安装(以相同的方式)其他软件包。有关Stackoverflow的详细分步指南:Unable to install Python packages using pip in Ubuntu Linux: InsecurePlatformWarning, SSLError, tlsv1 alert protocol version