Python引用旧SSL版本

2024-04-27 19:18:58 发布

您现在位置:Python中文网/ 问答频道 /正文

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

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

我想这是因为openssl已经过时了

所以我下载了openssl,从源代码构建并安装了它,现在当我运行下面的代码时,它看起来已经被正确地更新了。

openssl version
OpenSSL 1.0.1h 5 Jun 2014

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

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

Tags: 脚本ssl错误errorcertificateencodingdropboxnas
3条回答

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

  • --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

我有办法

brew install openssl
brew install python@2

那么

openssl version

以及

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

给了我相同的OpenSSL版本。

过了几天就开始工作了。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 $9}' | tr -d @ | xargs rm
 brew uninstall python
 brew uninstall openssl
 brew link --force openssl

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

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

将以下内容添加到MAC上~/.bash_配置文件中的路径

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

重新启动终端

 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"

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

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

应该提供最新版本的OPEN SSL版本

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

我和你一样有同样的问题,所以我找了好几个答案,但都没用。

  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

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

在MacOSX版本10.10和系统Python2.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/cell/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。

最后,你可以看到如下

$ python --version

Python 2.7.8

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

OpenSSL 1.0.1j 15 Oct 2014

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

相关问题 更多 >