Python 引用旧的 SSL 版本

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/24323858/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 04:25:52  来源:igfitidea点击:

Python referencing old SSL version

pythonsslopenssldropbox-apinas

提问by mburns02

I have a Dropbox upload script on an old nas box I have, recently I've been getting the following error

我在旧的 nas 盒子上有一个 Dropbox 上传脚本,最近我收到以下错误

SSL certificate error: [Errno 1] _ssl.c:504: error:0D0890A1:asn1 encoding routines:ASN1_verify:unknown message digest algorithm

SSL 证书错误:[Errno 1] _ssl.c:504:错误:0D0890A1:asn1 编码例程:ASN1_verify:未知消息摘要算法

I think this is due to openssl being out of date on the box

我认为这是因为 openssl 在盒子上已经过时了

So I download openssl, built it from source and installed it, now when I run the following it appears to be updated correctly.

因此,我下载了 openssl,从源代码构建并安装了它,现在当我运行以下命令时,它似乎已正确更新。

openssl version
OpenSSL 1.0.1h 5 Jun 2014

But it would appear Python is still referencing an old version, how would I update this?

但看起来 Python 仍在引用旧版本,我将如何更新它?

python -c "import ssl; print ssl.OPENSSL_VERSION"
OpenSSL 0.9.7m 23 Feb 2007

回答by user2434741

Please refer to http://rkulla.blogspot.kr/2014/03/the-path-to-homebrew.html.

请参考http://rkulla.blogspot.kr/2014/03/the-path-to-homebrew.html

I got the same issue like you, and so I have searched several answers but it didn't help me.

我遇到了和你一样的问题,所以我搜索了几个答案,但没有帮助我。

  1. Updating openssl in python 2.7
  2. Update OpenSSL on OS X with Homebrew
  3. https://apple.stackexchange.com/questions/126830/how-to-upgrade-openssl-in-os-x
  1. 在 python 2.7 中更新 openssl
  2. 使用 Homebrew 在 OS X 上更新 OpenSSL
  3. https://apple.stackexchange.com/questions/126830/how-to-upgrade-openssl-in-os-x

After upgrading openssl to 1.0.1j by homebrew on MAC, but system python still referred to old version 0.9.8. It turned out the python referred to openssl. So I have installed new python with brewed openssl and finished this issue on Mac, not yet Ubuntu.

在 MAC 上通过 homebrew 将 openssl 升级到 1.0.1j 后,但系统 python 仍然指的是旧版本 0.9.8。原来python指的是openssl。所以我用 brewed openssl 安装了新的 python 并在 Mac 上完成了这个问题,还不是 Ubuntu。

On Mac OS X version 10.10 and system python version 2.7.6, my procedure is as follows.

在 Mac OS X 版本 10.10 和系统 python 版本 2.7.6 上,我的程序如下。

  1. $ brew update
  2. $ brew install openssl.Then you can see openssl version 1.0.1j.
  3. $ brew link openssl --force
  4. $ brew install python --with-brewed-openssl.You have to install new python with brewed openssl. Then, you can see /usr/local/Cellar/python/2.7.8_2/bin/python.
  5. $ sudo ln -s /usr/local/Cellar/python/2.7.8_2/bin/python /usr/local/bin/python.Of course, /usr/local/* should be owned by $USER, not root, which is told by Ryan, but I used 'sudo'. And, before this instruction, I didn't have /usr/local/bin/python. After this instruction, you can use python version 2.7.8 not 2.7.6.
  1. $ brew update
  2. $ brew install openssl.然后就可以看到openssl 1.0.1j版本了。
  3. $ brew link openssl --force
  4. $ brew install python --with-brewed-openssl.您必须使用 brewed openssl 安装新的 python。然后,你可以看到/usr/local/Cellar/python/2.7.8_2/bin/python。
  5. $ sudo ln -s /usr/local/Cellar/python/2.7.8_2/bin/python /usr/local/bin/python.当然, /usr/local/* 应该由 $USER 拥有,而不是由 Ryan 告诉的 root 拥有,但我使用了 'sudo'。而且,在此指令之前,我没有 /usr/local/bin/python。在此说明之后,您可以使用 python 版本 2.7.8 而不是 2.7.6。

Finally, you can see as belows;

最后,您可以看到如下内容;

$ python --version

Python 2.7.8

蟒蛇 2.7.8

$ python -c "import ssl; print ssl.OPENSSL_VERSION"

OpenSSL 1.0.1j 15 Oct 2014

OpenSSL 1.0.1j 2014 年 10 月 15 日

Till now, I'm working on it on Ubuntu 12.04. If I have a solution for Ubuntu 12.04, then I will update my answer. I hope this procedure help you.

到现在为止,我正在 Ubuntu 12.04 上工作。如果我有 Ubuntu 12.04 的解决方案,那么我会更新我的答案。我希望这个程序对你有帮助。

回答by Shafi Ulla

This worked for me.

这对我有用。

python -c "import ssl; print ssl.OPENSSL_VERSION"
brew link openssl --force
brew install python --with-brewed-openssl
mv /usr/local/bin/python /usr/local/bin/python_old
sudo ln -s /usr/local/Cellar/python/2.7.11/bin/python /usr/local/bin/python

回答by greenFedoraHat

I did all the steps above and still was getting the same problem. I solved my problem adding the following command after all the ones listed on the previous answers:

我做了上面的所有步骤,但仍然遇到同样的问题。我解决了在之前答案中列出的所有命令之后添加以下命令的问题:

brew unlink openssl --force --overwrite python && brew link openssl --force --overwrite python

Hope it helps anyone :)

希望它可以帮助任何人:)

回答by Arun Ganesan

Got this working after several days. MAC OS X El Captian or greater

几天后得到了这个工作。MAC OS X El Captian 或更高版本

 sudo rm -rf /Library/Frameworks/Python.framework/Versions/2.7
 sudo rm -rf "/Applications/Python 2.7"
 cd /usr/local/bin/
 ls -l /usr/local/bin | grep '../Library/Frameworks/Python.framework/Versions/2.7' | awk '{print }' | tr -d @ | xargs rm
 brew uninstall python
 brew uninstall openssl
 brew link --force openssl

Now install python and openssl again using brew.

现在使用 brew 再次安装 python 和 openssl。

 brew install openssl
 brew install python --with-brewed-openssl

Add the following to the PATH in ~/.bash_profile on your MAC

将以下内容添加到 MAC 上 ~/.bash_profile 中的 PATH

 vi ~/.bash_profile
 export PATH=/usr/local/opt/openssl/bin:/usr/local/opt/python/libexec/bin:$PATH

restart the terminal

重启终端

 python --version (verify if it is picking up the right version)
 openssl version -a (verify if it is picking up the right version)
 python -c "import ssl; print ssl.OPENSSL_VERSION"

(note: if you installed Python3, you'll have to update the printsyntax in the inline compiler step)

(注意:如果您安装了 Python3,则必须在内print联编译器步骤中更新语法)

python -c "import ssl; print(ssl.OPENSSL_VERSION)"

should give you the latest version OPEN SSL version

应该给你最新版本的 OPEN SSL 版本

回答by Guglie

2018 on MacOS
I tried with the other answers without success:

2018 在 MacOS 上
我尝试了其他答案但没有成功:

  • The --with-brewed-openssloption gives Warning: python: this formula has no --with-brewed-openssl option so it will be ignored!
  • and the command brew link openssl --forcegives Warning: Refusing to link: openssl
  • --with-brewed-openssl选项给出Warning: python: this formula has no --with-brewed-openssl option so it will be ignored!
  • 命令brew link openssl --force给出Warning: Refusing to link: openssl


I got it working with

我得到了它

brew install openssl
brew install python@2

Then

然后

openssl version

and

python -c "import ssl; print ssl.OPENSSL_VERSION"

gave me the same OpenSSL version.

给了我相同的 OpenSSL 版本。

回答by JHLynch

I found I had to change the PATH to use the system (upgraded) SSL:

我发现我必须更改 PATH 才能使用系统(升级后的)SSL:

$ pip install --editable .

Obtaining file:///Users/jhlynch/Projects/flaskr
Collecting flask (from flaskr==0.0.0)
  Could not fetch URL https://pypi.python.org/simple/flask/: There was a problem confirming the ssl certificate: [SSL: TLSV1_ALERT_PROTOCOL_VERSION] tlsv1 alert protocol version (_ssl.c:661) - skipping
  Could not find a version that satisfies the requirement flask (from flaskr==0.0.0) (from versions: )
No matching distribution found for flask (from flaskr==0.0.0)

$ python -c "import ssl; print(ssl.OPENSSL_VERSION)"

OpenSSL 0.9.8zh 14 Jan 2016                      <<< note older version


$ echo $PATH
/Library/Frameworks/Python.framework/Versions/2.7/bin:/Library/Frameworks/Python.framework/Versions/3.6/bin:/Users/jhlynch/.nix-profile/bin:/Users/jhlynch/.nix-profile/sbin:/Users/jhlynch/.nix-profile/lib/kde4/libexec:/nix/var/nix/profiles/default/bin:/nix/var/nix/profiles/default/sbin:/nix/var/nix/profiles/default/lib/kde4/libexec:/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin

$ PATH="/usr/local/bin:/usr/local/sbin:${PATH}"

$ export PATH

$ python -c "import ssl; print(ssl.OPENSSL_VERSION)"

OpenSSL 1.0.2o  27 Mar 2018                       <<< note newer version

$ pip install --editable .

Obtaining file:///Users/jhlynch/Projects/flaskr
Collecting flask (from flaskr==0.0.0)
  Downloading https://files.pythonhosted.org/packages/77/32/e3597cb19ffffe724ad4bf0beca4153419918e7fa4ba6a34b04ee4da3371/Flask-0.12.2-py2.py3-none-any.whl (83kB)
...                <<< works this time!

回答by Benny K

OSX Sierra, Python 3.7, same problem, re-installing/updating Python & OpenSSL did not help with this particular issue (but was useful anyway, I guess).

OSX Sierra,Python 3.7,同样的问题,重新安装/更新 Python 和 OpenSSL 对这个特定问题没有帮助(但我猜无论如何还是有用的)。

Basic solution: clean up your $PATHin .bash_profile! I had to manually removebunch of stale dirs (/Library/Frameworks/Python.framework/Versions/3.4/bin:/Library/Frameworks/Python.framework/Versions/3.6/bin:/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages:/Library/Frameworks/Python.framework/Versions/2.7/bin)

,基本解决方案:清理你的$ PATH.bash_profile!我不得不手动删除一堆陈旧的目录 ( /Library/Frameworks/Python.framework/Versions/3.4/bin:/Library/Frameworks/Python.framework/Versions/3.6/bin:/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages:/Library/Frameworks/Python.framework/Versions/2.7/bin)

Then run:

然后运行:

brew link --overwrite --dry-run python

brew link --overwrite --dry-run python

If everything looks OK, repeat without --dry-run:

如果一切正常,请重复以下操作--dry-run

brew link --overwrite python

brew link --overwrite python

Result:

结果:

Linking /usr/local/Cellar/python/3.7.0... 25 symlinks created
~
$  python3 -c "import ssl; print(ssl.OPENSSL_VERSION)"
OpenSSL 1.0.2p  14 Aug 2018

回答by mxbn

Had to modify this answerto work with Homebrew 2.2.4 and python3 on MacOS 10.15.3:

必须修改此答案才能在 MacOS 10.15.3 上使用 Homebrew 2.2.4 和 python3:

brew unlink openssl python3 && brew link openssl python3
echo 'export PATH="/usr/local/opt/[email protected]/bin:$PATH"' >> ~/.bash_profile

回答by Derek Hill

I'm running running OSX 10.14.5 Mojave and using pyenv.

我正在运行 OSX 10.14.5 Mojave 并使用 pyenv。

The problem I had was that when Homebrew upgraded openssl, Python was left looking for the old version. python -c "import ssl; print(ssl.OPENSSL_VERSION)"gave the error:

我遇到的问题是,当 Homebrew 升级 openssl 时,Python 一直在寻找旧版本。python -c "import ssl; print(ssl.OPENSSL_VERSION)"给出了错误:

Library not loaded: /usr/local/opt/openssl/lib/libssl.1.0.0.dylib

库未加载:/usr/local/opt/openssl/lib/libssl.1.0.0.dylib

After trying lots of things, the solution turned out to be:

在尝试了很多事情之后,解决方案竟然是:

pyenv uninstall 3.6.8
pyenv install 3.6.8

The magic line in the builds logs was:

构建日志中的神奇之处是:

python-build: use [email protected] from homebrew

python-build:使用自制软件中的 [email protected]