python - 如何在不使用自制软件的情况下为 Python 2.7 更新 OpenSSL

标签 python macos python-2.7 ssl openssl

当使用 Python 2.7.14 执行不同的脚本时,我不断遇到似乎导致我的 OpenSSL 安装的错误。

例如使用请求时:

requests.exceptions.SSLError: [SSL: SSLV3_ALERT_HANDSHAKE_FAILURE] sslv3 alert handshake failure (_ssl.c:661)

我在:

  • python 2.7.14
  • MacOS Mojave 版本 10.14.3
  • 使用 homebrew ! (并且不愿意)

Mac 操作系统使用 LibreSSL :

$ openssl version -a
LibreSSL 2.6.5
built on: date not available
platform: information not available
options:  bn(64,64) rc4(ptr,int) des(idx,cisc,16,int) blowfish(idx) 
compiler: information not available
OPENSSLDIR: "/private/etc/ssl"

$ which openssl
/usr/bin/openssl

但是,我的 Python 安装(来自源代码)都使用 OpenSSL - 两个不同的版本:

$ python2.7 -c 'import ssl; print ssl.OPENSSL_VERSION'
OpenSSL 0.9.8zh 14 Jan 2016

$ python3.7 -c 'import ssl; print(ssl.OPENSSL_VERSION)'
OpenSSL 1.1.0i  14 Aug 2018

我想更新与 Python 2.7 一起使用的 OpenSSL,而不使用 homebrew(也不是 Anaconda),也不使用额外的包,例如 pyOpenSSL.

我在网上找到的大多数解决方案都建议使用 homebrew,因此不要回答我的问题:

我的 Python 版本都不是使用 homebrew 安装的,我想保持干净,以免操作系统设置进一步复杂化。

考虑到安装了不同版本的OpenSSL,是不是应该按照this suggestion并将 Python 2.7 链接到更新的 OpenSSL 版本?

  • 这是前进的最佳方式吗?
  • 会出什么问题?
  • 什么是可行的替代方案?
  • 有没有学习在 Mac 上浏览 SSL-Python-jungle 的好资源?

最佳答案

鉴于当前安装的版本是 python.org 本身提供的版本,只需再次下载并安装最新版本就足够了。鉴于 2.7.14 二进制文件中的旧版本 OpenSSL,它看起来像是针对 MacOS 附带的旧版本编译的。在 2.7.15 中,这发生了变化,可以在 download page 上看到:

Attention macOS users: as of 2.7.15, all python.org macOS installers ship with a builtin copy of OpenSSL.

因此,您只需安装 python.org 提供的 2.7.15 官方版本,即可在 Python 2.7 中获得最新的 OpenSSL。请注意,您已经拥有的 Python 3.7 也是这种情况。

关于python - 如何在不使用自制软件的情况下为 Python 2.7 更新 OpenSSL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56696237/

相关文章:

python - python 中 'argv' 的确切术语是什么?

python - 停用词出现在最有影响力的词中

python - 使用 random 函数随机化计划任务

cocoa - 我如何在 Cocoa 中获取应用程序菜单

c++ - 如何在 C++11 的 Mac OS X 上命名 std::thread?

python-2.7 - 测试所有元素是否在 Python 中的另一个列表中

python - 从另一个列表中删除列表列表

python - 如何增加脚本运行时迭代的数组数量?

python - 如何在图坐标中指定matplotlib中的图例位置

objective-c - 如何保持调整大小的窗口的纵横比?