我安装某些python软件包时遇到了麻烦,因为我有TLS 1.0版本。如何升级到TLS 1.2?

python -c "import urllib2; import json; print(json.loads(urllib2.urlopen('https://www.howsmyssl.com/a/check').read())['tls_version'])"
TLS 1.0

我的macOS版本:10.13.4(17E202)
python版本:Python 2.7.13
openssl版本:LibreSSL 2.2.7

我试图升级openssl,但它没有升级LibreSSL。我记得一年前我遇到了一些与openssl的问题,我可能已经手动将其链接了,或者::(

最佳答案

即使brew下载了opensl的​​新版本,旧版本仍与openssl命令一起使用。所以我disabled csrutil摆脱了/usr/bin/openssl中的openssl符号链接(symbolic link):

sudo ln -s /usr/local/Cellar/openssl/1.0.2o_1/bin/openssl /usr/bin/openssl

然后,openssl版本是最新的:
~ openssl version
OpenSSL 1.0.2o  27 Mar 2018

但是python仍然使用openssl的旧版本:
~ python -c "import ssl; print(ssl.OPENSSL_VERSION)"
OpenSSL 0.9.8zh 14 Jan 2016

因此,将再次禁用csrutil,并将继续修复python版本。

我删除了我可以找到的python2安装,或多或少地遵循以下步骤:
brew uninstall python@2
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安装了python2,它使用了正确的openssl:
~ brew install python@2
~ python -c "import urllib2,json; print(json.loads(urllib2.urlopen('https://www.howsmyssl.com/a/check').read())['tls_version'])"
TLS 1.2

关于python - 在macOS上将TLS 1.0升级到TLS 1.2,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/50271295/

10-12 16:47
查看更多