【问题标题】:'SSLError' installing with pip使用 pip 安装 SSLError
【发布时间】:2019-10-30 20:43:17
【问题描述】:

我正在尝试在 Windows 10 上安装 Django。

无论我尝试在 cmd 上使用 pip 安装什么,我都会收到这些错误

Collecting django
  Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1056)'))': /simple/django/
  Retrying (Retry(total=3, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1056)'))': /simple/django/
  Retrying (Retry(total=2, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1056)'))': /simple/django/
  Retrying (Retry(total=1, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1056)'))': /simple/django/
  Retrying (Retry(total=0, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1056)'))': /simple/django/
  Could not fetch URL https://pypi.org/simple/django/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/django/ (Caused by SSLError(SSLError(1, '[SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1056)'))) - skipping
  Could not find a version that satisfies the requirement django (from versions: )
No matching distribution found for django
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: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1056)'))) - skipping

我从其他问题中尝试了很多东西,但都没有奏效。

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

pip install --trusted-host pypi.python.org --trusted-host files.pythonhosted.org --trusted-host pypi.org django

【问题讨论】:

  • 您的防火墙不允许 pip 连接到互联网,因此请允许来自 windows 防火墙的 pip 并且它将起作用
  • 确保您有强大的互联网连接并允许防火墙连接到 pip 参考此 github.com/pypa/pip/issues/6152
  • @Exprator 互联网连接不是问题,所以它可能是公司的防火墙,我想我自己不能允许。还有其他安装 django 的方法吗?
  • 进行跟踪路由可能会揭示它被阻塞的位置。从cmd,尝试tracert pypi.python.org。如果您看到显示有* 的地址,则表示它无法到达该跃点。
  • @FlipperPA 我确实 * 显示了,所以我猜它无法到达....这可能是因为公司的防火墙,我尝试了一些带有代理的命令,但似乎没有任何效果

标签: python django windows ssl


【解决方案1】:

正确设置我的代理也为我解决了这个问题。问题是我为我的 HTTPS_PROXY 和 https_proxy 环境变量使用了 https 协议。

用途:

HTTPS_PROXY="http://username:password@proxy.example.com:8080"
https_proxy="http://username:password@proxy.example.com:8080"

不要使用:

HTTPS_PROXY="https://username:password@proxy.example.com:8080"
https_proxy="https://username:password@proxy.example.com:8080"

【讨论】:

  • 工作!下次开发人员不知道事情是如何运作的......
  • 哇。它确实有效 - 使用 http 而不是 https 作为 HTTPS_PROXY
  • 工作。刚刚还使用我正在使用的代理创建了一个环境变量。无需不升级到 pip 到 20.3.1。
  • 7 年后..仍然很好..Python 3.9.4
  • 以防万一有人来到这里,在 powershell 中,这对我有用:$env:HTTPS_PROXY = "http://proxy:port" $env:https_proxy = "http://proxy:port"
【解决方案2】:

如果有人仍然遇到此问题,请尝试查找并删除 OpenSSL(操作系统级别安装),如果它已安装在您的系统中。

就我而言,我很久以前在 Windows 10 上安装了 openssl(用于其他一些开发任务)并忘记了它,这是罪魁祸首。我卸载了它,它解决了这个问题

【讨论】:

    【解决方案3】:

    对我来说,它是系统代理,据我所知,trusted-host 标志在 pip 想要查询不安全的 http 索引并且 pip 默认只查询 SSL 安全索引时使用。

    【讨论】:

      【解决方案4】:

      我的 pip 工作正常(Win7,python 3.8.6),直到我将 pip 从版本 20.2.1 升级到 20.3.1,之后我还收到 SSL: WRONG_VERSION_NUMBER 错误。这个是可以重现的,我卸载重装了好几次才确认。

      解决方案(好吧,解决方法):不要将 pip 升级到 20.3.1。

      注意:pip 20.3.1 在我的 Win10/python 3.9.1 环境中运行良好。

      【讨论】:

      • 可能是唯一有效的答案!
      • 我通过反复试验发现 20.2.4 是适用于 python 3.7.9 的最高版本
      • 我在 Win10 上全新安装 Python 3.9.1 并升级到 pip 21.0.1 时也遇到了这个问题。解决方案是重新安装 Python 并在 20.2.3 版本上使用 pip。我们有一个 SSL 拦截代理,我尝试设置 pip 21.0.1 似乎不使用的 global.cert。我提出了一个问题:github.com/pypa/pip/issues/9614
      • @LuciusSilanus 你是怎么解决你的问题的,可以分享一下吗?
      • @UğurGürkanTosun 我必须为 pip 20.2.4 下载一个轮子并从轮子文件中安装它 (stackoverflow.com/a/28002930/4871972)
      【解决方案5】:

      我问了一位自动知道该怎么做的同事。我只需要设置代理变量: “设置 https_proxy=http://username:password@proxy.example.com:8080” “设置 http_proxy=http://username:password@proxy.example.com:8080” 它有效

      【讨论】:

        【解决方案6】:

        检查您的代理设置。你可以使用这个命令

        pip install <package> --trusted-host pypi.org --trusted-host files.pythonhosted.org --proxy="<IP>:<port>"
        

        【讨论】:

        • 我仍然有这个错误:“连接被 'ConnectTimeoutError(, 'Connection to 192.168.0.254 timed out. (connect timeout=15)')': /simple/django/"
        • 这个命令可以正常工作pip install &lt;package&gt; --trusted-host pypi.org --trusted-host files.pythonhosted.org --proxy="http://&lt;username&gt;:&lt;password&gt;@&lt;IP&gt;:&lt;port&gt;"
        • 也为我工作。谢谢!!
        猜你喜欢
        • 2018-09-27
        • 2020-10-23
        • 2011-01-13
        • 2021-04-14
        • 2017-11-19
        • 2021-02-26
        • 2021-05-31
        • 2014-08-31
        相关资源
        最近更新 更多