pip无法与pypi服务器建立安全连接

时间:2015-05-13 13:04:02

标签: python ubuntu ssl pip

昨天我尝试用pip安装一些python包,它就行不通了。

paquete@paquete-ultrabook:~$ pip install isort -v
Downloading/unpacking isort
  Could not fetch URL https://pypi.python.org/simple/isort/: connection error: [Errno 0] _ssl.c:344: error:00000000:lib(0):func(0):reason(0)
  Will skip URL https://pypi.python.org/simple/isort/ when looking for download links for isort
  Could not fetch URL https://pypi.python.org/simple/: connection error: [Errno 0] _ssl.c:344: error:00000000:lib(0):func(0):reason(0)
  Will skip URL https://pypi.python.org/simple/ when looking for download links for isort
  Cannot fetch index base URL https://pypi.python.org/simple/
  Could not fetch URL https://pypi.python.org/simple/isort/: connection error: [Errno 0] _ssl.c:344: error:00000000:lib(0):func(0):reason(0)
  Will skip URL https://pypi.python.org/simple/isort/ when looking for download links for isort
  Could not find any downloads that satisfy the requirement isort
Cleaning up...
  Removing temporary dir /tmp/pip_build_paquete...
No distributions at all found for isort
Exception information:
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 122, in main
    status = self.run(options, args)
  File "/usr/lib/python2.7/dist-packages/pip/commands/install.py", line 278, in run
    requirement_set.prepare_files(finder, force_root_egg_info=self.bundle, bundle=self.bundle)
  File "/usr/lib/python2.7/dist-packages/pip/req.py", line 1177, in prepare_files
    url = finder.find_requirement(req_to_install, upgrade=self.upgrade)
  File "/usr/lib/python2.7/dist-packages/pip/index.py", line 277, in find_requirement
    raise DistributionNotFound('No distributions at all found for %s' % req)
DistributionNotFound: No distributions at all found for isort

Storing debug log for failure in /tmp/tmpl86YQE

我一直在互联网上寻找答案而没有成功。 2012年的很多答案都表明会降级,但是那个麻烦的错误已经解决了。

paquete@paquete-ultrabook:~$ pip -V
pip 1.5.4 from /usr/lib/python2.7/dist-packages (python 2.7)

有些人的python解释器存在问题,但它似乎与服务器连接良好。

paquete@paquete-ultrabook:~$ python
Python 2.7.6 (default, Mar 22 2014, 22:59:56) 
[GCC 4.8.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import httplib
>>> conn = httplib.HTTPSConnection("pypi.python.org")
>>> conn.request("GET","/simple/")
>>> res = conn.getresponse()
>>> print res.status, res.reason
200 OK

作为补充信息,几周前我做了一个基本的全新安装。所有包都会发生这种情况。我已经通过apt安装了所有内容,所以这似乎是任何想法?

更新 根据@andersson的建议,我试图安装pip的最新版本。然后这就开出了

paquete@paquete-ultrabook:~$ sudo python3 Downloads/get-pip.py -v
The directory '/home/paquete/.cache/pip/log' or its parent directory is not owned by the current user and the debug log has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
The directory '/home/paquete/.cache/pip/http' or its parent directory is not owned by the current user and the cache has been disabled. Please check the permissions and owner of that directory. If executing pip with sudo, you may want sudo's -H flag.
Starting new HTTPS connection (1): pypi.python.org
There was an error checking the latest version of pip
Traceback (most recent call last):
  File "/tmp/tmp8w985p0e/pip.zip/pip/_vendor/requests/packages/urllib3/util/ssl_.py", line 253, in ssl_wrap_socket
    context.load_verify_locations(ca_certs)
ssl.SSLError: unknown error (_ssl.c:2734)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/tmp/tmp8w985p0e/pip.zip/pip/_vendor/requests/adapters.py", line 370, in send
    timeout=timeout
  File "/tmp/tmp8w985p0e/pip.zip/pip/_vendor/requests/packages/urllib3/connectionpool.py", line 544, in urlopen
    body=body, headers=headers)
  File "/tmp/tmp8w985p0e/pip.zip/pip/_vendor/requests/packages/urllib3/connectionpool.py", line 341, in _make_request
    self._validate_conn(conn)
  File "/tmp/tmp8w985p0e/pip.zip/pip/_vendor/requests/packages/urllib3/connectionpool.py", line 762, in _validate_conn
    conn.connect()
  File "/tmp/tmp8w985p0e/pip.zip/pip/_vendor/requests/packages/urllib3/connection.py", line 238, in connect
    ssl_version=resolved_ssl_version)
  File "/tmp/tmp8w985p0e/pip.zip/pip/_vendor/requests/packages/urllib3/util/ssl_.py", line 255, in ssl_wrap_socket
    raise SSLError(e)
pip._vendor.requests.packages.urllib3.exceptions.SSLError: unknown error (_ssl.c:2734)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/tmp/tmp8w985p0e/pip.zip/pip/utils/outdated.py", line 126, in pip_version_check
    headers={"Accept": "application/json"},
  File "/tmp/tmp8w985p0e/pip.zip/pip/_vendor/requests/sessions.py", line 476, in get
    return self.request('GET', url, **kwargs)
  File "/tmp/tmp8w985p0e/pip.zip/pip/download.py", line 367, in request
    return super(PipSession, self).request(method, url, *args, **kwargs)
  File "/tmp/tmp8w985p0e/pip.zip/pip/_vendor/requests/sessions.py", line 464, in request
    resp = self.send(prep, **send_kwargs)
  File "/tmp/tmp8w985p0e/pip.zip/pip/_vendor/requests/sessions.py", line 576, in send
    r = adapter.send(request, **kwargs)
  File "/tmp/tmp8w985p0e/pip.zip/pip/_vendor/cachecontrol/adapter.py", line 46, in send
    resp = super(CacheControlAdapter, self).send(request, **kw)
  File "/tmp/tmp8w985p0e/pip.zip/pip/_vendor/requests/adapters.py", line 431, in send
    raise SSLError(e, request=request)
pip._vendor.requests.exceptions.SSLError: unknown error (_ssl.c:2734)

这似乎是一个普遍的问题。

3 个答案:

答案 0 :(得分:2)

我的问题略有不同。看起来{2016}在2016年6月更新了https://pypi.python.org/simple/证书,因此如果您的操作系统日期早于该日期,则无论是否安装了正确的CA证书,您都无法验证证书。

答案 1 :(得分:0)

我还有一些默认(1.5.4)点数版本的问题。你能成功地将pip更新到最新版本(6.1.1),或者你已经尝试过,并且两个pip版本的安装都失败了吗?

答案 2 :(得分:-1)

及时解决:

sudo update-ca-certificates