Skip to content

Instantly share code, notes, and snippets.

@chrisdpa-tvx
Last active April 19, 2018 08:04
Show Gist options
  • Save chrisdpa-tvx/2237074ed416dce84034e201429a5b6e to your computer and use it in GitHub Desktop.
Save chrisdpa-tvx/2237074ed416dce84034e201429a5b6e to your computer and use it in GitHub Desktop.
Updating Python 2.7 to use TLS1.2

Updating python to use TLS1.2 is now required (this is the problem the guys in devops encountered) and here is how to do it.

If you are using virtualenv you’ll need to deactivate it:

deactivate

then use brew to install the latest version of python and openssl:

brew install python@2

Once that is done link python to the new version:

brew link --overwrite python@2

Check you python has updated:

python -V Python 2.7.14

use `hash -r` if you have any issues

You’ll need to recreate you virtualenvs but first update virtualenv:

pip install virtualenv

Now create your virtual env and re-run for you project:

pip install -r requirements

if you get this, check that everything has run properly:

Could not fetch URL https://pypi.python.org/simple/ansible/: There was a problem confirming the ssl certificate: [SSL: TLSV1_ALERT_PROTOCOL_VERSION]

Then you can check your version of python supports TLS1.2:

➜  python -c "import json, urllib2; print json.load(urllib2.urlopen('https://www.howsmyssl.com/a/check'))['tls_version']"
TLS 1.2

I found pip 9 worked best with my project:

pip install pip==9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment