简体   繁体   English

OS X 上的 Python 和 OpenSSL 版本参考问题

[英]Python and OpenSSL version reference issue on OS X

Trying to resolve an OpenSSL version issue I'm having.试图解决我遇到的 OpenSSL 版本问题。

It seems that I have three different versions of OpenSSL on my Mac.我的 Mac 上似乎有三个不同版本的 OpenSSL。

  1. Python 2.7.11 has version 0.9.7m: Python 2.7.11 版本为 0.9.7m:

     python -c "import ssl; print ssl.OPENSSL_VERSION" OpenSSL 0.9.7m 23 Feb 2007
  2. At the Terminal:在航站楼:

     openssl version OpenSSL 1.0.1h 5 Jun 2014
  3. Recently Compiled / Installed:最近编译/安装:

     /usr/local/ssl/bin/openssl OpenSSL> version OpenSSL 1.0.2h 3 May 2016 OpenSSL>

I recently upgraded my OS X to 10.11.5.我最近将我的 OS X 升级到 10.11.5。 In the process, caused an issue for previously working python scripts.在此过程中,导致以前工作的 python 脚本出现问题。 Below is the error message snippet:以下是错误消息片段:

Python Error Message: Python 错误信息:

 You are linking against OpenSSL 0.9.8, which is no longer *
 RuntimeError: You are linking against OpenSSL 0.9.8, which is no longer support by the OpenSSL project. You need to upgrade to a newer version of OpenSSL.

(* - yes, this is how the error message looks like. It's trimmed in the middle of the sentence.) (* - 是的,这就是错误消息的样子。它在句子中间被剪掉了。)

Any recommendations on resolving this issue would be greatly appreciated.任何有关解决此问题的建议将不胜感激。 What I'd like is to have Python reference the OpenSSL version 1.0.2h vs the outdated version 0.9.7m.我想要的是让 Python 参考 OpenSSL 版本 1.0.2h 与过时的版本 0.9.7m。

I've tried installing Python and OpenSSL many times using various post / blogs for guidance without any luck.我已经多次尝试使用各种帖子/博客作为指导安装 Python 和 OpenSSL,但没有任何运气。

Use this as a workaround:将此用作解决方法:

export CRYPTOGRAPHY_ALLOW_OPENSSL_098=1

This appears to be a recent check of the hazmat cryptography library.这似乎是最近对危险品加密库的检查。 You can see the source code at:您可以在以下位置查看源代码:

https://github.com/pyca/cryptography/blob/master/src/cryptography/hazmat/bindings/openssl/binding.py#L221 https://github.com/pyca/cryptography/blob/master/src/cryptography/hazmat/bindings/openssl/binding.py#L221

The CRYPTOGRAPHY_ALLOW_OPENSSL_098 environment variable downgrades the error to a deprecation warning, if you are willing to take the risk.如果您愿意承担风险, CRYPTOGRAPHY_ALLOW_OPENSSL_098环境变量会将错误降级为弃用警告。 I also ran into this on OS X in just the past day, so something changed recently.就在过去的一天,我也在 OS X 上遇到了这个问题,所以最近发生了一些变化。

You can install a version of python that uses a newer version of openssl.您可以安装使用较新版本 openssl 的 python 版本。

First you can brew install a new version of open SSL首先你可以 brew install 一个新版本的 open SSL

brew update
brew install openssl
brew link --force openssl

You should see a newer version with你应该看到一个更新的版本

openssl version -a

Then you can install a different version of python which uses that newer version of openssl.然后你可以安装不同版本的python,它使用较新版本的openssl。 If you use pyenv , that would be:如果您使用pyenv ,那将是:

CFLAGS="-I$(brew --prefix openssl)/include" \
LDFLAGS="-L$(brew --prefix openssl)/lib" \
pyenv install -v 3.4.3

You can find more information about installing a version of python with a brew installed version of openssl here: https://github.com/yyuu/pyenv/wiki/Common-build-problems您可以在此处找到有关使用 brew 安装版本的 openssl 安装 python 版本的更多信息: https : //github.com/yyuu/pyenv/wiki/Common-build-problems

This problem almost kills me!!!! 这个问题差点让我丧命! Finally my guy solved this only by lowering the version of the package "paramiko" from 2.* to 1.*(like 1.15.4 I set)can solve! 最后,我的家伙仅通过将软件包“ paramiko”的版本从2. *降低到1。*(例如我设定的1.15.4)就可以解决该问题!

If you are getting You are linking against OpenSSL 1.0.0 then use export CRYPTOGRAPHY_ALLOW_OPENSSL_098=1 environment variable to bypass it. 如果You are linking against OpenSSL 1.0.0使用export CRYPTOGRAPHY_ALLOW_OPENSSL_098=1环境变量绕过它。 Thanks @braddock 谢谢@braddock

SOLVED NO HACKS, none of the above worked for me. 解决不了任何麻烦,以上都不对我有用。 I ended up taking a simpler and uncomplicated approach.... 我最终采取了一种简单而不复杂的方法。

  1. Install python 2.7.13 from the official site, it actually installs as the default python, replacing the old python system wide. 从官方站点安装python 2.7.13,它实际上是作为默认python安装的,取代了整个python系统。

https://www.python.org/downloads/mac-osx/ https://www.python.org/downloads/mac-osx/

  1. Upgrade openssl after the python install. python安装后升级openssl。

sudo pip install --upgrade pyOpenSSL sudo pip install-升级pyOpenSSL

  1. You will have to re-install all your python modules ( because you replaced python ), I strongly recommend using pip. 您将必须重新安装所有python模块(因为您替换了python),我强烈建议您使用pip。 After a few minutes of pip installs my default OSX python was upgraded, I had openssl upgraded, and I had all my modules ( including django running ). 在安装了pip几分钟后,我的默认OSX python升级了,openssl升级了,所有模块(包括正在运行的django)都安装了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM