Python引用旧的SSL版本

时间:2014-06-20 09:17:24

标签: python ssl openssl dropbox-api nas

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

  

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

我认为这是因为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

9 个答案:

答案 0 :(得分:18)

几天后工作了。 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_profile中的PATH

 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版本

答案 1 :(得分:6)

2018年在MacOS上
我试着用其他答案没有成功:

  • --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版本。

答案 2 :(得分:5)

请参阅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
  4. 通过MAC上的homebrew将openssl升级到1.0.1j后,系统python仍然引用旧版本0.9.8。原来,这个python被称为openssl。所以我用brewed openssl安装了新的python并在Mac上完成了这个问题,还没有Ubuntu。

    在Mac OS X版本10.10和系统python版本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所有,而不是root,Ryan告诉我,但我使用了' sudo'。并且,在此指令之前,我没有/ usr / local / bin / python。在这条指令之后,你可以使用python版本2.7.8而不是2.7.6。
    6. 最后,您可以看到以下内容;

      $ python --version
      
        

      Python 2.7.8

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

      OpenSSL 1.0.1j 2014年10月15日

      直到现在,我正在使用Ubuntu 12.04进行处理。如果我有Ubuntu 12.04的解决方案,那么我将更新我的答案。我希望这个程序可以帮助你。

答案 3 :(得分:3)

我发现我必须更改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!

答案 4 :(得分:2)

这对我有用。

java.lang.IllegalStateException: Fail to request https://sonar.forge.mycompany.com:9000/api/system/status
.
.
.
Caused by: javax.net.ssl.SSLException: Unrecognized SSL message, plaintext connection?

答案 5 :(得分:1)

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

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

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

答案 6 :(得分:1)

OSX Sierra,Python 3.7,相同的问题,重新安装/更新Python和OpenSSL并没有解决此特定问题(但我想还是很有用的。)

基本解决方案:清理.bash_profile中的$ PATH !我不得不手动删除一堆陈旧的迪尔(/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

然后运行:

brew link --overwrite --dry-run python

如果一切正常,请重复而不使用--dry-run

brew link --overwrite python

结果:

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

答案 7 :(得分:1)

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

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

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

尝试了很多事情之后,解决方案变成了:

pyenv uninstall 3.6.8
pyenv install 3.6.8

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

python-build:使用自制软件中的openssl@1.1

答案 8 :(得分:0)

必须修改this answer以在MacOS 10.15.3上与Homebrew 2.2.4和python3配合使用:

brew unlink openssl python3 && brew link openssl python3
echo 'export PATH="/usr/local/opt/openssl@1.1/bin:$PATH"' >> ~/.bash_profile