由于过时的证书,Mac上的SSLError pip失败 - 如何恢复?

时间:2018-04-24 10:08:43

标签: python ssl pip ssl-certificate

在MacOS(10.11.6)上使用pip搜索或安装软件包时,我收到类似于下面重现的SSL错误。

python2和python3都会出现问题。我通过www.python.org作为框架获得了版本(2.7.14和3.6.5)。 pip的版本是9.0.1。问题是新的(2018年4月),似乎与OSX的更新有关。

如何从这个问题中恢复?

$ pip2 search numpy

Exception:
Traceback (most recent call last):
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip/basecommand.py", line 215, in main
    status = self.run(options, args)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip/commands/search.py", line 45, in run
    pypi_hits = self.search(query, options)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip/commands/search.py", line 62, in search
    hits = pypi.search({'name': query, 'summary': query}, 'or')
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xmlrpclib.py", line 1243, in __call__
    return self.__send(self.__name, args)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/xmlrpclib.py", line 1602, in __request
    verbose=self.__verbose
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip/download.py", line 775, in request
    headers=headers, stream=True)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip/_vendor/requests/sessions.py", line 522, in post
    return self.request('POST', url, data=data, json=json, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip/download.py", line 386, in request
    return super(PipSession, self).request(method, url, *args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip/_vendor/requests/sessions.py", line 475, in request
    resp = self.send(prep, **send_kwargs)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip/_vendor/requests/sessions.py", line 596, in send
    r = adapter.send(request, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip/_vendor/cachecontrol/adapter.py", line 47, in send
    resp = super(CacheControlAdapter, self).send(request, **kw)
  File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/pip/_vendor/requests/adapters.py", line 497, in send
    raise SSLError(e, request=request)
SSLError: [SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:661)

2 个答案:

答案 0 :(得分:4)

有两种方法可以从这个问题中恢复。

解决方案1 ​​。可以阅读here,Python.org网站停止了对旧版TLS版本的支持,这些版本会中断pip < 9.0.3。提供了一个新版本的pip,但由于不能简单地通过破坏的pip进行更新,因此必须引导安装。这对我有用:

# For python2
curl https://bootstrap.pypa.io/get-pip.py | python2
# For python3 (haven't tested this myself)
curl https://bootstrap.pypa.io/get-pip.py | python3

这些命令的积分可以追溯到this SO post

解决方案2 。对于Python 3.6框架,在Install Certificates.command下部署并安装了脚本/Applications/Python 3.6/。执行它解决了问题,但仅适用于pip3

答案 1 :(得分:1)

您只需要重新安装Python

brew reinstall python