其他分享
首页 > 其他分享> > pip联网问题 SSLError(SSLError(1, ‘[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:748

pip联网问题 SSLError(SSLError(1, ‘[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:748

作者:互联网

有时候你在conda中使用pip,即使在pip.conf中设置了trusted-host,还是不起作用,连不上网:

$ pip search absl-py
WARNING: pip is being invoked by an old script wrapper. This will fail in a future version of pip.
Please see https://github.com/pypa/pip/issues/5599 for advice on fixing the underlying issue.
To avoid this problem you can invoke Python with '-m pip' instead of running pip directly.
WARNING: Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:748)'),)': /pypi
WARNING: Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:748)'),)': /pypi
WARNING: Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:748)'),)': /pypi
WARNING: Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:748)'),)': /pypi
WARNING: Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:748)'),)': /pypi
ERROR: Exception:
Traceback (most recent call last):
  File "/home/user1/.local/lib/python3.6/site-packages/pip-20.2.2-py3.6.egg/pip/_vendor/urllib3/connectionpool.py", line 667, in urlopen
    self._prepare_proxy(conn)
  File "/home/user1/.local/lib/python3.6/site-packages/pip-20.2.2-py3.6.egg/pip/_vendor/urllib3/connectionpool.py", line 930, in _prepare_proxy
    conn.connect()
  File "/home/user1/.local/lib/python3.6/site-packages/pip-20.2.2-py3.6.egg/pip/_vendor/urllib3/connection.py", line 370, in connect
    ssl_context=context,
  File "/home/user1/.local/lib/python3.6/site-packages/pip-20.2.2-py3.6.egg/pip/_vendor/urllib3/util/ssl_.py", line 377, in ssl_wrap_socket
    return context.wrap_socket(sock, server_hostname=server_hostname)
  File "/home/user1/anaconda3/envs/mxgpu/lib/python3.6/ssl.py", line 401, in wrap_socket
    _context=self, _session=session)
  File "/home/user1/anaconda3/envs/mxgpu/lib/python3.6/ssl.py", line 808, in __init__
    self.do_handshake()
  File "/home/user1/anaconda3/envs/mxgpu/lib/python3.6/ssl.py", line 1061, in do_handshake
    self._sslobj.do_handshake()
  File "/home/user1/anaconda3/envs/mxgpu/lib/python3.6/ssl.py", line 683, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:748)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/user1/.local/lib/python3.6/site-packages/pip-20.2.2-py3.6.egg/pip/_vendor/requests/adapters.py", line 449, in send
    timeout=timeout
  File "/home/user1/.local/lib/python3.6/site-packages/pip-20.2.2-py3.6.egg/pip/_vendor/urllib3/connectionpool.py", line 765, in urlopen
    **response_kw
  File "/home/user1/.local/lib/python3.6/site-packages/pip-20.2.2-py3.6.egg/pip/_vendor/urllib3/connectionpool.py", line 765, in urlopen
    **response_kw
  File "/home/user1/.local/lib/python3.6/site-packages/pip-20.2.2-py3.6.egg/pip/_vendor/urllib3/connectionpool.py", line 765, in urlopen
    **response_kw
  [Previous line repeated 1 more times]
  File "/home/user1/.local/lib/python3.6/site-packages/pip-20.2.2-py3.6.egg/pip/_vendor/urllib3/connectionpool.py", line 725, in urlopen
    method, url, error=e, _pool=self, _stacktrace=sys.exc_info()[2]
  File "/home/user1/.local/lib/python3.6/site-packages/pip-20.2.2-py3.6.egg/pip/_vendor/urllib3/util/retry.py", line 439, in increment
    raise MaxRetryError(_pool, url, error or ResponseError(cause))
pip._vendor.urllib3.exceptions.MaxRetryError: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /pypi (Caused by SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:748)'),))

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "/home/user1/.local/lib/python3.6/site-packages/pip-20.2.2-py3.6.egg/pip/_internal/cli/base_command.py", line 216, in _main
    status = self.run(options, args)
  File "/home/user1/.local/lib/python3.6/site-packages/pip-20.2.2-py3.6.egg/pip/_internal/commands/search.py", line 60, in run
    pypi_hits = self.search(query, options)
  File "/home/user1/.local/lib/python3.6/site-packages/pip-20.2.2-py3.6.egg/pip/_internal/commands/search.py", line 80, in search
    hits = pypi.search({'name': query, 'summary': query}, 'or')
  File "/home/user1/anaconda3/envs/mxgpu/lib/python3.6/xmlrpc/client.py", line 1112, in __call__
    return self.__send(self.__name, args)
  File "/home/user1/anaconda3/envs/mxgpu/lib/python3.6/xmlrpc/client.py", line 1452, in __request
    verbose=self.__verbose
  File "/home/user1/.local/lib/python3.6/site-packages/pip-20.2.2-py3.6.egg/pip/_internal/network/xmlrpc.py", line 42, in request
    headers=headers, stream=True)
  File "/home/user1/.local/lib/python3.6/site-packages/pip-20.2.2-py3.6.egg/pip/_vendor/requests/sessions.py", line 578, in post
    return self.request('POST', url, data=data, json=json, **kwargs)
  File "/home/user1/.local/lib/python3.6/site-packages/pip-20.2.2-py3.6.egg/pip/_internal/network/session.py", line 421, in request
    return super(PipSession, self).request(method, url, *args, **kwargs)
  File "/home/user1/.local/lib/python3.6/site-packages/pip-20.2.2-py3.6.egg/pip/_vendor/requests/sessions.py", line 530, in request
    resp = self.send(prep, **send_kwargs)
  File "/home/user1/.local/lib/python3.6/site-packages/pip-20.2.2-py3.6.egg/pip/_vendor/requests/sessions.py", line 643, in send
    r = adapter.send(request, **kwargs)
  File "/home/user1/.local/lib/python3.6/site-packages/pip-20.2.2-py3.6.egg/pip/_vendor/cachecontrol/adapter.py", line 53, in send
    resp = super(CacheControlAdapter, self).send(request, **kw)
  File "/home/user1/.local/lib/python3.6/site-packages/pip-20.2.2-py3.6.egg/pip/_vendor/requests/adapters.py", line 514, in send
    raise SSLError(e, request=request)
pip._vendor.requests.exceptions.SSLError: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /pypi (Caused by SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:748)'),))

首先打开firefox,确认你能连到外网。访问个百度什么的。
然后,从报错来看 是pip连接 pypi.org 连不上。
这时候你需要手动指定 pypi.org 为信任:

比如这样:

$ pip search absl-py --trusted-host=pypi.org

标签:certificate,CERTIFICATE,user1,py,python3.6,pip,SSLError,home,line
来源: https://blog.csdn.net/qxqxqzzz/article/details/110631553