Python 在macOS上将TLS 1.0升级为TLS 1.2

Python 在macOS上将TLS 1.0升级为TLS 1.2,python,macos,openssl,tls1.2,Python,Macos,Openssl,Tls1.2,我在安装一些python软件包时遇到了问题,因为我有TLS1.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版本

我在安装一些python软件包时遇到了问题,因为我有TLS1.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下载了新版本的openssl,但旧版本与命令
openssl
一起使用。因此我想在
/usr/bin/openssl
中去掉openssl符号链接:

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

你应该使用某种virtualenv机制,而不仅仅是明目张胆地删除股票Python,因为它可能会被其他东西使用……还记得如果你对答案满意,请将答案勾选为已解决,这样问题就结束了。