使用pip安装包时出现ssl错误

时间:2017-07-01 19:45:56

标签: python ubuntu ssl pip

这是一个使用ubuntu 16.04的新服务器,我在网上有一些其他的ubuntu服务器,除了这个之外没有任何问题。我不知道为什么会这样。

我已经尝试过&p 34; pip install --index-url = http://pypi.python.org/simple/ --trusted-host pypi.python.org request"," pip --cert GlobalSign_Root_CA .pem安装请求"," pip --cert DigiCert_Global_Root_CA.pem安装请求"。没有解决这个错误。

ubuntu 16.04

pip 8.1.1 from /usr/lib/python2.7/dist-packages (python 2.7)

curl的一些测试结果

root@ubuntu:~# curl https://api.ipify.org/
curl: (35) gnutls_handshake() failed: The TLS connection was non-properly terminated.
root@ubuntu:~# curl http://api.ipify.org/
curl: (52) Empty reply from server
root@ubuntu:~# curl  https://pypi.python.org
curl: (35) gnutls_handshake() failed: The TLS connection was non-properly terminated.
root@ubuntu:~# curl  http://pypi.python.org
curl: (52) Empty reply from server

同样的ssl问题曾经发生过apt-get update。在安装了全新的ubuntu后,它已经消失了,但保留了pip ssl错误。

使用apt-get update

更新结果
root@ubuntu:~# sudo apt-get update
Hit:1 https://mirrors.tuna.tsinghua.edu.cn/ubuntu xenial InRelease
Get:2 https://mirrors.tuna.tsinghua.edu.cn/ubuntu xenial-updates InRelease [102 kB]
Get:3 https://mirrors.tuna.tsinghua.edu.cn/ubuntu xenial-backports InRelease [102 kB]
Get:4 https://mirrors.tuna.tsinghua.edu.cn/ubuntu xenial-security InRelease [102 kB]
Get:5 https://mirrors.tuna.tsinghua.edu.cn/ubuntu xenial-updates/main amd64 Packages [572 kB]
Get:6 https://mirrors.tuna.tsinghua.edu.cn/ubuntu xenial-updates/main i386 Packages [552 kB]
Get:7 https://mirrors.tuna.tsinghua.edu.cn/ubuntu xenial-updates/universe amd64 Packages [490 kB]
Get:8 https://mirrors.tuna.tsinghua.edu.cn/ubuntu xenial-updates/universe i386 Packages [472 kB]
Fetched 2,393 kB in 4s (535 kB/s)                        
Reading package lists... Done

pip --cert GlobalSign_Root_CA.pem安装请求

Collecting requests
Exception:
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 209, in main
    status = self.run(options, args)
  File "/usr/lib/python2.7/dist-packages/pip/commands/install.py", line 328, in run
    wb.build(autobuilding=True)
  File "/usr/lib/python2.7/dist-packages/pip/wheel.py", line 748, in build
    self.requirement_set.prepare_files(self.finder)
  File "/usr/lib/python2.7/dist-packages/pip/req/req_set.py", line 360, in prepare_files
    ignore_dependencies=self.ignore_dependencies))
  File "/usr/lib/python2.7/dist-packages/pip/req/req_set.py", line 512, in _prepare_file
    finder, self.upgrade, require_hashes)
  File "/usr/lib/python2.7/dist-packages/pip/req/req_install.py", line 273, in populate_link
    self.link = finder.find_requirement(self, upgrade)
  File "/usr/lib/python2.7/dist-packages/pip/index.py", line 442, in find_requirement
    all_candidates = self.find_all_candidates(req.name)
  File "/usr/lib/python2.7/dist-packages/pip/index.py", line 400, in find_all_candidates
    for page in self._get_pages(url_locations, project_name):
  File "/usr/lib/python2.7/dist-packages/pip/index.py", line 545, in _get_pages
    page = self._get_page(location)
  File "/usr/lib/python2.7/dist-packages/pip/index.py", line 648, in _get_page
    return HTMLPage.get_page(link, session=self.session)
  File "/usr/lib/python2.7/dist-packages/pip/index.py", line 757, in get_page
    "Cache-Control": "max-age=600",
  File "/usr/share/python-wheels/requests-2.9.1-py2.py3-none-any.whl/requests/sessions.py", line 480, in get
    return self.request('GET', url, **kwargs)
  File "/usr/lib/python2.7/dist-packages/pip/download.py", line 378, in request
    return super(PipSession, self).request(method, url, *args, **kwargs)
  File "/usr/share/python-wheels/requests-2.9.1-py2.py3-none-any.whl/requests/sessions.py", line 468, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/share/python-wheels/requests-2.9.1-py2.py3-none-any.whl/requests/sessions.py", line 576, in send
    r = adapter.send(request, **kwargs)
  File "/usr/share/python-wheels/CacheControl-0.11.5-py2.py3-none-any.whl/cachecontrol/adapter.py", line 46, in send
    resp = super(CacheControlAdapter, self).send(request, **kw)
  File "/usr/share/python-wheels/requests-2.9.1-py2.py3-none-any.whl/requests/adapters.py", line 376, in send
    timeout=timeout
  File "/usr/share/python-wheels/urllib3-1.13.1-py2.py3-none-any.whl/urllib3/connectionpool.py", line 610, in urlopen
    _stacktrace=sys.exc_info()[2])
  File "/usr/share/python-wheels/urllib3-1.13.1-py2.py3-none-any.whl/urllib3/util/retry.py", line 228, in increment
    total -= 1
TypeError: unsupported operand type(s) for -=: 'Retry' and 'int'

点子搜索请求

Exception:
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/pip/basecommand.py", line 209, in main
    status = self.run(options, args)
  File "/usr/lib/python2.7/dist-packages/pip/commands/search.py", line 43, in run
    pypi_hits = self.search(query, options)
  File "/usr/lib/python2.7/dist-packages/pip/commands/search.py", line 60, in search
    hits = pypi.search({'name': query, 'summary': query}, 'or')
  File "/usr/lib/python2.7/xmlrpclib.py", line 1243, in __call__
    return self.__send(self.__name, args)
  File "/usr/lib/python2.7/xmlrpclib.py", line 1602, in __request
    verbose=self.__verbose
  File "/usr/lib/python2.7/dist-packages/pip/download.py", line 764, in request
    headers=headers, stream=True)
  File "/usr/share/python-wheels/requests-2.9.1-py2.py3-none-any.whl/requests/sessions.py", line 511, in post
    return self.request('POST', url, data=data, json=json, **kwargs)
  File "/usr/lib/python2.7/dist-packages/pip/download.py", line 378, in request
    return super(PipSession, self).request(method, url, *args, **kwargs)
  File "/usr/share/python-wheels/requests-2.9.1-py2.py3-none-any.whl/requests/sessions.py", line 468, in request
    resp = self.send(prep, **send_kwargs)
  File "/usr/share/python-wheels/requests-2.9.1-py2.py3-none-any.whl/requests/sessions.py", line 576, in send
    r = adapter.send(request, **kwargs)
  File "/usr/share/python-wheels/CacheControl-0.11.5-py2.py3-none-any.whl/cachecontrol/adapter.py", line 46, in send
    resp = super(CacheControlAdapter, self).send(request, **kw)
  File "/usr/share/python-wheels/requests-2.9.1-py2.py3-none-any.whl/requests/adapters.py", line 447, in send
    raise SSLError(e, request=request)
SSLError: EOF occurred in violation of protocol (_ssl.c:590)

pip install -vvv requests

Converted retries value: Retry(total=5, connect=None, read=None, redirect=None) -> Retry(total=Retry(total=5, connect=None, read=None, redirect=None), connect=None, read=None, redirect=None)
Converted retries value: Retry(total=5, connect=None, read=None, redirect=None) -> Retry(total=Retry(total=5, connect=None, read=None, redirect=None), connect=None, read=None, redirect=None)
Collecting requests
  1 location(s) to search for versions of requests:
  * https://pypi.python.org/simple/requests/
  Getting page https://pypi.python.org/simple/requests/
  Starting new HTTPS connection (1): pypi.python.org
  Could not fetch URL https://pypi.python.org/simple/requests/: connection error: EOF occurred in violation of protocol (_ssl.c:645) - skipping
  Could not find a version that satisfies the requirement requests (from versions: )
Cleaning up...
No matching distribution found for requests
Exception information:
Traceback (most recent call last):
  File "/root/code/nlp/.env/lib/python3.5/site-packages/pip/basecommand.py", line 209, in main
    status = self.run(options, args)
  File "/root/code/nlp/.env/lib/python3.5/site-packages/pip/commands/install.py", line 328, in run
    wb.build(autobuilding=True)
  File "/root/code/nlp/.env/lib/python3.5/site-packages/pip/wheel.py", line 748, in build
    self.requirement_set.prepare_files(self.finder)
  File "/root/code/nlp/.env/lib/python3.5/site-packages/pip/req/req_set.py", line 360, in prepare_files
    ignore_dependencies=self.ignore_dependencies))
  File "/root/code/nlp/.env/lib/python3.5/site-packages/pip/req/req_set.py", line 512, in _prepare_file
    finder, self.upgrade, require_hashes)
  File "/root/code/nlp/.env/lib/python3.5/site-packages/pip/req/req_install.py", line 273, in populate_link
    self.link = finder.find_requirement(self, upgrade)
  File "/root/code/nlp/.env/lib/python3.5/site-packages/pip/index.py", line 491, in find_requirement
    'No matching distribution found for %s' % req
pip.exceptions.DistributionNotFound: No matching distribution found for requests
Converted retries value: Retry(total=0, connect=None, read=None, redirect=None) -> Retry(total=Retry(total=0, connect=None, read=None, redirect=None), connect=None, read=None, redirect=None)
Converted retries value: Retry(total=0, connect=None, read=None, redirect=None) -> Retry(total=Retry(total=0, connect=None, read=None, redirect=None), connect=None, read=None, redirect=None)
Starting new HTTPS connection (1): pypi.python.org
There was an error checking the latest version of pip
Traceback (most recent call last):
  File "/root/code/nlp/.env/share/python-wheels/urllib3-1.13.1-py2.py3-none-any.whl/urllib3/connectionpool.py", line 560, in urlopen
    body=body, headers=headers)
  File "/root/code/nlp/.env/share/python-wheels/urllib3-1.13.1-py2.py3-none-any.whl/urllib3/connectionpool.py", line 346, in _make_request
    self._validate_conn(conn)
  File "/root/code/nlp/.env/share/python-wheels/urllib3-1.13.1-py2.py3-none-any.whl/urllib3/connectionpool.py", line 787, in _validate_conn
    conn.connect()
  File "/root/code/nlp/.env/share/python-wheels/urllib3-1.13.1-py2.py3-none-any.whl/urllib3/connection.py", line 252, in connect
    ssl_version=resolved_ssl_version)
  File "/root/code/nlp/.env/share/python-wheels/urllib3-1.13.1-py2.py3-none-any.whl/urllib3/util/ssl_.py", line 305, in ssl_wrap_socket
    return context.wrap_socket(sock, server_hostname=server_hostname)
  File "/usr/lib/python3.5/ssl.py", line 377, in wrap_socket
    _context=self)
  File "/usr/lib/python3.5/ssl.py", line 752, in __init__
    self.do_handshake()
  File "/usr/lib/python3.5/ssl.py", line 988, in do_handshake
    self._sslobj.do_handshake()
  File "/usr/lib/python3.5/ssl.py", line 633, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLEOFError: EOF occurred in violation of protocol (_ssl.c:645)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/root/code/nlp/.env/share/python-wheels/requests-2.9.1-py2.py3-none-any.whl/requests/adapters.py", line 376, in send
    timeout=timeout
  File "/root/code/nlp/.env/share/python-wheels/urllib3-1.13.1-py2.py3-none-any.whl/urllib3/connectionpool.py", line 589, in urlopen
    raise SSLError(e)
requests.packages.urllib3.exceptions.SSLError: EOF occurred in violation of protocol (_ssl.c:645)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/root/code/nlp/.env/lib/python3.5/site-packages/pip/utils/outdated.py", line 126, in pip_version_check
    headers={"Accept": "application/json"},
  File "/root/code/nlp/.env/share/python-wheels/requests-2.9.1-py2.py3-none-any.whl/requests/sessions.py", line 480, in get
    return self.request('GET', url, **kwargs)
  File "/root/code/nlp/.env/lib/python3.5/site-packages/pip/download.py", line 378, in request
    return super(PipSession, self).request(method, url, *args, **kwargs)
  File "/root/code/nlp/.env/share/python-wheels/requests-2.9.1-py2.py3-none-any.whl/requests/sessions.py", line 468, in request
    resp = self.send(prep, **send_kwargs)
  File "/root/code/nlp/.env/share/python-wheels/requests-2.9.1-py2.py3-none-any.whl/requests/sessions.py", line 576, in send
    r = adapter.send(request, **kwargs)
  File "/root/code/nlp/.env/share/python-wheels/CacheControl-0.11.5-py2.py3-none-any.whl/cachecontrol/adapter.py", line 46, in send
    resp = super(CacheControlAdapter, self).send(request, **kw)
  File "/root/code/nlp/.env/share/python-wheels/requests-2.9.1-py2.py3-none-any.whl/requests/adapters.py", line 447, in send
    raise SSLError(e, request=request)
requests.exceptions.SSLError: EOF occurred in violation of protocol (_ssl.c:645)

1 个答案:

答案 0 :(得分:0)

由于我的路由器中的shadowsocks有些配置错误,它现在已经修复并正常工作。