代码之家  ›  专栏  ›  技术社区  ›  Josh Peak

ImportError使用Anaconda Python在Windows 10 Git Bash上导入\u ssl

  •  0
  • Josh Peak  · 技术社区  · 7 年前

    我在一个有自签名证书的公司代理后面工作。我已经详细地记录了这一点。

    问题 TLS/SSL模块没有正确加载,甚至无法验证证书。

    • 视窗10
    • git版本2.19.0.windows.1

    问题

    python -c "import ssl"
    

    我可以让它在Anaconda提示符下工作,但不能在gitbash中工作。为什么会有区别?

    我从最新的Anaconda发行版2018.12的基本安装开始,并尝试安装 redis .

    $ pip install redis
    pip is configured with locations that require TLS/SSL, however the ssl module in Python is not available.
    Collecting redis
      Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by 'SSLError("Can't connect to HTTPS URL because the SSL module is not available.")': /simple/redis/
      ...
      Could not fetch URL https://pypi.org/simple/redis/: There was a problem confirming the ssl certificate: HTTPSConnectionPool(host='pypi.org', port=443): Max retries exceeded with url: /simple/redis/ (Caused by SSLError("Can't connect to HTTPS URL because the SSL module is not available.")) - skipping
      Could not find a version that satisfies the requirement redis (from versions: )
    No matching distribution found for redis
    

    所以这很奇怪。 SSLError("Can't connect to HTTPS URL because the SSL module is not available.") ssl .

    $ python -c "import ssl"
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "C:\Users\username\AppData\Local\Continuum\anaconda3\lib\ssl.py", line 98, in <module>
        import _ssl             # if we can't import it, let the error propagate
    ImportError: DLL load failed: The specified procedure could not be found.
    

    (base) C:\Users\username> python -c "import ssl"
    
    (base) C:\Users\username> 
    

    (base) C:\Users\username> conda deactivate
    C:\Users\username>
    C:\Users\username> python -c "import ssl"
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "C:\Users\username\AppData\Local\Continuum\anaconda3\lib\ssl.py", line 98, in <module>
        import _ssl             # if we can't import it, let the error propagate
    ImportError: DLL load failed: The specified procedure could not be found.
    

    停用基本conda环境后,我可以在Anaconda提示符中复制错误。

    摘要

    _ssl.pyd C:\Users\username\AppData\Local\Continuum\anaconda3\DLLs 它确实可以工作,但是我缺少了一些东西,或者不知道如何进一步调试,以找出它在gitbash中不工作的原因。

    我不明白如何调试python如何加载dll以及Anaconda环境如何影响这一点。

    1 回复  |  直到 7 年前
        1
  •  0
  •   Josh Peak    7 年前

    2.19.0 2.20.1

    [http]
        sslBackend=schannel
    

    更新:Git V2.20.0发行说明

    https://raw.githubusercontent.com/git/git/master/Documentation/RelNotes/2.20.0.txt

    • 在具有最新cURL库的平台上,http.sslBackend文件配置 变量可用于在运行时选择不同的SSL后端。 Windows端口使用此机制在OpenSSL和 安全通道,同时通过HTTPS协议交谈。

    绩效、内部实施、发展支持等。

    • 在Windows端口上加载dll的方式已经改进。

    这些似乎是gitbash中唯一可能导致此问题的更改。我以为它使用的是Windows安全通道,但也许它以前使用的是gitbash OpenSSL,现在正在更新 schannel

        2
  •  -1
  •   adiga    7 年前

    也许这会有帮助。提示来自 Git 2.22.0 Setup