【问题标题】:Pip SSL Error on WindowsWindows 上的 Pip SSL 错误
【发布时间】:2018-10-01 06:36:39
【问题描述】:

我在 Windows 7 64 位环境中使用 Python 3.x,但无法完全控制入站/出站流量处理。直到本周,我已经能够将--trusted-host pypi.python.org 标志与 pip 一起使用,并且一切正常。本周,即使使用 --trusted-host 标志,我也开始收到以下错误。

Could not fetch URL https://pypi.python.org/simple/pytubes/: There was a probl
em confirming the ssl certificate: [SSL: CERTIFICATE_VERIFY_FAILED] certificate
verify failed (_ssl.c:720) - skipping

鉴于本周 pypi 的更改,我尝试将 --trusted-host 标志更改为 https://files.pythonhosted.org/packages/,但这似乎没有帮助。

我还尝试下载和安装 certifi、wincerstore 和 win32 certifi 的轮子以及针对此类问题的其他 stackoverflow 建议,例如 digistore .pem cert 和 pip.ini 文件,但均未成功。

pip install fails with "connection error: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:598)"

最后我尝试按照此处的说明将 pip 从 pip 9.0.3 升级到 pip 10:https://pip.pypa.io/en/stable/installing/

对于 curl 下载,我必须传入 -k,运行 python get-pip.py 失败,并出现与 pip 类似的 ssl 错误:

 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:749)'),)': /simple/pip/
  Could not fetch URL https://pypi.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749)'),)) - skipping
  Could not find a version that satisfies the requirement pip (from versions: )
No matching distribution found for pip
Could not fetch URL https://pypi.org/simple/pip/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/pip/ (Caused by SSLError(SSLError(1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c:749)'),)) - skipping

感谢任何有关后续步骤的建议,因为 .pem 文件、Python CA 包和 --trusted-host 标志没有解决问题

编辑:

来自以下答案的 pip 中带有 -vvv 标志的新输出。

 > pip install pytubes -vvv
Config variable 'Py_DEBUG' is unset, Python ABI tag may be incorrect
Config variable 'WITH_PYMALLOC' is unset, Python ABI tag may be incorrect
Collecting pytubes
  1 location(s) to search for versions of pytubes:
  * https://pypi.python.org/simple/pytubes/
  Getting page https://pypi.python.org/simple/pytubes/
  Looking up "https://pypi.python.org/simple/pytubes/" in the cache
  No cache entry available
  Starting new HTTPS connection (1): pypi.python.org
  Could not fetch URL https://pypi.python.org/simple/pytubes/: There was a probl
em confirming the ssl certificate: [SSL: CERTIFICATE_VERIFY_FAILED] certificate
verify failed (_ssl.c:749) - skipping
  Could not find a version that satisfies the requirement pytubes (from versions
: )
Cleaning up...
No matching distribution found for pytubes
Exception information:
Traceback (most recent call last):
  File "C:\ProgramData\Anaconda3\lib\site-packages\pip\basecommand.py", line 215
, in main
    status = self.run(options, args)
  File "C:\ProgramData\Anaconda3\lib\site-packages\pip\commands\install.py", lin
e 335, in run
    wb.build(autobuilding=True)
  File "C:\ProgramData\Anaconda3\lib\site-packages\pip\wheel.py", line 749, in b
uild
    self.requirement_set.prepare_files(self.finder)
  File "C:\ProgramData\Anaconda3\lib\site-packages\pip\req\req_set.py", line 380
, in prepare_files
    ignore_dependencies=self.ignore_dependencies))
  File "C:\ProgramData\Anaconda3\lib\site-packages\pip\req\req_set.py", line 554
, in _prepare_file
    require_hashes
  File "C:\ProgramData\Anaconda3\lib\site-packages\pip\req\req_install.py", line
 278, in populate_link
    self.link = finder.find_requirement(self, upgrade)
  File "C:\ProgramData\Anaconda3\lib\site-packages\pip\index.py", line 514, in f
ind_requirement
    'No matching distribution found for %s' % req
pip.exceptions.DistributionNotFound: No matching distribution found for pytubes
Looking up "https://pypi.python.org/pypi/pip/json" in the cache
No cache entry available
Starting new HTTPS connection (1): pypi.python.org
There was an error checking the latest version of pip
Traceback (most recent call last):
  File "C:\ProgramData\Anaconda3\lib\site-packages\pip\_vendor\requests\packages
\urllib3\connectionpool.py", line 595, in urlopen
    chunked=chunked)
  File "C:\ProgramData\Anaconda3\lib\site-packages\pip\_vendor\requests\packages
\urllib3\connectionpool.py", line 352, in _make_request
    self._validate_conn(conn)
  File "C:\ProgramData\Anaconda3\lib\site-packages\pip\_vendor\requests\packages
\urllib3\connectionpool.py", line 831, in _validate_conn
    conn.connect()
  File "C:\ProgramData\Anaconda3\lib\site-packages\pip\_vendor\requests\packages
\urllib3\connection.py", line 289, in connect
    ssl_version=resolved_ssl_version)
  File "C:\ProgramData\Anaconda3\lib\site-packages\pip\_vendor\requests\packages
\urllib3\util\ssl_.py", line 308, in ssl_wrap_socket
    return context.wrap_socket(sock, server_hostname=server_hostname)
  File "C:\ProgramData\Anaconda3\lib\ssl.py", line 401, in wrap_socket
    _context=self, _session=session)
  File "C:\ProgramData\Anaconda3\lib\ssl.py", line 808, in __init__
    self.do_handshake()
  File "C:\ProgramData\Anaconda3\lib\ssl.py", line 1061, in do_handshake
    self._sslobj.do_handshake()
  File "C:\ProgramData\Anaconda3\lib\ssl.py", line 683, in do_handshake
    self._sslobj.do_handshake()
ssl.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed (_ssl.c
:749)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\ProgramData\Anaconda3\lib\site-packages\pip\_vendor\requests\adapters
.py", line 423, in send
    timeout=timeout
  File "C:\ProgramData\Anaconda3\lib\site-packages\pip\_vendor\requests\packages
\urllib3\connectionpool.py", line 621, in urlopen
    raise SSLError(e)
pip._vendor.requests.packages.urllib3.exceptions.SSLError: [SSL: CERTIFICATE_VER
IFY_FAILED] certificate verify failed (_ssl.c:749)

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:\ProgramData\Anaconda3\lib\site-packages\pip\utils\outdated.py", line
126, in pip_version_check
    headers={"Accept": "application/json"},
  File "C:\ProgramData\Anaconda3\lib\site-packages\pip\_vendor\requests\sessions
.py", line 488, in get
    return self.request('GET', url, **kwargs)
  File "C:\ProgramData\Anaconda3\lib\site-packages\pip\download.py", line 386, i
n request
    return super(PipSession, self).request(method, url, *args, **kwargs)
  File "C:\ProgramData\Anaconda3\lib\site-packages\pip\_vendor\requests\sessions
.py", line 475, in request
    resp = self.send(prep, **send_kwargs)
  File "C:\ProgramData\Anaconda3\lib\site-packages\pip\_vendor\requests\sessions
.py", line 596, in send
    r = adapter.send(request, **kwargs)
  File "C:\ProgramData\Anaconda3\lib\site-packages\pip\_vendor\cachecontrol\adap
ter.py", line 47, in send
    resp = super(CacheControlAdapter, self).send(request, **kw)
  File "C:\ProgramData\Anaconda3\lib\site-packages\pip\_vendor\requests\adapters
.py", line 497, in send
    raise SSLError(e, request=request)
pip._vendor.requests.exceptions.SSLError: [SSL: CERTIFICATE_VERIFY_FAILED] certi
ficate verify failed (_ssl.c:749)

【问题讨论】:

  • 需要信任的不是主机。消息说证书有问题。当我打开 https://pypi.org/simple/pytubes/ 时,我没有收到此错误,Chrome 也没有显示任何问题。您可能在使用 Fiddler 吗?在咖啡店工作或使用任何拦截流量并使用自签名证书的东西?
  • PS 我也不必使用--trusted-host
  • 我在企业环境中,所以完全有可能在我们的设置中存在与流量交互的东西,但我并不是 100% 了解所有内容的路由方式。无论如何让我验证一下?此外,如果我在 Chrome 中转到 pypi.org/simple/pytubes,我不会遇到任何问题并且拥有安全标记。

标签: python windows ssl pip


【解决方案1】:

我在 venv 中工作时收到 SSL 模块错误。后来发现问题出在其他软件修改的dll版本上。

我不知道它是否适合你。安装 openSSL 文件会将所有 dll 更新到其较新版本。

链接:https://slproweb.com/products/Win32OpenSSL.html

无需任何更改。安装就好了。

【讨论】:

    【解决方案2】:

    我更改了 IE 设置(IE 设置-Internet 选项-高级-未选中的 ssl 设置)它开始工作..

    【讨论】:

      【解决方案3】:

      我知道这个问题很久以前就已经回答过了,但是对于遇到这个问题的其他人,如果你有 Fiddler 打开并捕获数据包,关闭它可以修复错误

      【讨论】:

        【解决方案4】:

        pip install cryptography 抛出错误:

        由于 EnvironmentError 无法安装软件包:HTTPSConnectionPool(host='files.pythonhosted.org'

        无法获取 URL https://pypi.org/simple/cryptography/:确认 ssl 证书时出现问题:

        尝试将这些 URL 添加为受信任的主机,并且成功了:

        pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org cryptography
        

        【讨论】:

        • 虽然这解决了问题,但我认为无论谁想要使用它,都必须首先找出 SSL 失败的原因。尤其是在windows环境下。
        【解决方案5】:

        以下解决方案对我有用:

        1. 转到run。输入%appdata%
        2. 转到文件夹pip 并编辑pip.ini 文件。
        3. 如果该文件夹不存在,则创建一个并创建一个 pip.ini 文件并在文本编辑器中进行编辑。
        4. 添加以下内容:
        [global]
        trusted-host = pypi.python.org
                       pypi.org
                       files.pythonhosted.org
                       raw.githubusercontent.com
                       github.com
        

        【讨论】:

          【解决方案6】:

          我觉得最好的解决方案是:- 访问与 SSL 相关的文件。在安装位置找到该文件夹​​,即 session.py 所在的位置。 (我猜是在文件夹~~~₩pip₩vender₩requests)

          打开sessions.py,修改self.verify = True为self.verify = False

          使用受信任的主机代码安装,如下所示

          【讨论】:

          • 这个答案似乎不完整。 “使用以下受信任的主机代码安装”中的代码在哪里?
          【解决方案7】:

          我有同样的问题,我在安装 tensorflow 的过程中解决了它。以下是分步解决方案:

          1. 访问与 SSL 相关的文件。在安装位置找到sessions.py 所在的文件夹。 (我猜是在文件夹~~~₩pip₩vender₩requests)

          2. 打开sessions.py,修改self.verify = Trueself.verify = False

          3. 使用受信任的主机代码安装,如下所示

            pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org <package name> 
            

          【讨论】:

            【解决方案8】:

            最终对我有用的是添加所有属于新 pypi 路由的域。

            pip install --trusted-host pypi.org --trusted-host pypi.python.org --trusted-host files.pythonhosted.org <package>
            

            也可以在 pip.ini 文件中设置。

            【讨论】:

              【解决方案9】:

              您可能使用了一个讨厌的代理服务器,该服务器通过中间人攻击来进行深度数据包检查。您需要从您的代理管理员处获取 CA 证书文件,以便告诉 Python 一切正常。您也可以从您的网络浏览器或任何其他配置为与代理一起使用的东西中提取此信息。

              获得证书后,可以将其添加到 certifi 包的 cacert.pem 文件中,也可以直接在 pip.conf 文件中使用--cert 选项或global.cert 告诉 pip。

              【讨论】:

              • 我认为这是其中的一部分。我现在正在与其他人一起帮助 CA 和 SSL 组件。我将使用最终解决方案更新此内容并标记适当的答案。
              猜你喜欢
              • 2011-11-23
              • 2011-05-19
              • 2017-09-03
              • 2018-11-21
              • 1970-01-01
              • 2018-09-24
              • 1970-01-01
              • 1970-01-01
              • 2015-07-21
              相关资源
              最近更新 更多