python调用git在windows,ImportError在Windows 10 Git Bash上使用Anaconda Python导入_ssl

Context

I am working behind a corporate proxy with a self-signed certificate. I have documented this extensively.

The issue now is that TLS/SSL module is not loading correctly to even verify the certificates.

Windows 10

Anaconda 2018.12 (Python 3.7.1)

git version 2.19.0.windows.1

Question

python -c "import ssl"

I can get it to work in Anaconda Prompt, but not in Git Bash. Why is there a difference?

Steps

Using Git Bash

I started with the basic install of the latest (at time of writing) Anaconda distribution 2018.12 and tried to install 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

So that is weird. SSLError("Can't connect to HTTPS URL because the SSL module is not available."). So I tried just importing ssl.

$ python -c "import ssl"

Traceback (most recent call last):

File "", line 1, in

File "C:\Users\username\AppData\Local\Continuum\anaconda3\lib\ssl.py", line 98, in

import _ssl # if we can't import it, let the error propagate

ImportError: DLL load failed: The specified procedure could not be found.

Anaconda Prompt

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

(base) C:\Users\username>

No errors. Just a blank line.

(base) C:\Users\username> conda deactivate

C:\Users\username>

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

Traceback (most recent call last):

File "", line 1, in

File "C:\Users\username\AppData\Local\Continuum\anaconda3\lib\ssl.py", line 98, in

import _ssl # if we can't import it, let the error propagate

ImportError: DLL load failed: The specified procedure could not be found.

After deactivating the base conda environment I can replicate the error in an Anaconda Prompt.

Summary

So obviously the _ssl.pyd file in C:\Users\username\AppData\Local\Continuum\anaconda3\DLLs does work but there is something I'm missing or do not know how to debug further to figure out why it does not work in Git Bash.

I do not understand how to debug how python loads DLLs and how Anaconda environments influences this.

解决方案

Since git bash seemed to be what was different I tried updating it from 2.19.0 to 2.20.1 and it now works in Git Bash.

Which is weird since both versions were configured to use the Windows Secure Channel backend for TLS/SSL.

[http]

sslBackend=schannel

Update: Git V2.20.0 release notes

Updates since v2.19

UI, Workflows & Features

On platforms with recent cURL library, http.sslBackend configuration

variable can be used to choose a different SSL backend at runtime.

The Windows port uses this mechanism to switch between OpenSSL and

Secure Channel while talking over the HTTPS protocol.

Performance, Internal Implementation, Development Support etc.

The way DLLs are loaded on the Windows port has been improved.

These seem to be the only changes in Git Bash that could have caused the issue. I thought it was using Windows Secure Channel but perhaps it was using Git Bash OpenSSL previously and updating points it at schannel

Alternatively there was an issue with how the msys terminal emulator loaded in DLLs.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值