OSX + homebrew users:
You can get the latest updates to the recipe:
brew reinstall python
But if you still get the issue, e.g. maybe you have upgraded your OS, then you may need to get the latest openssl first. You can check which version and where it is used from:
openssl version -a
which openssl
To get the latest openssl:
brew update
brew install openssl
brew link --overwrite --dry-run openssl # safety first.
brew link openssl --overwrite
This may issue a warning:
bash-4.3$ brew link --overwrite --dry-run openssl
Warning: Refusing to link: openssl Linking keg-only openssl means you may end up linking against the insecure, deprecated system OpenSSL while using the headers from Homebrew's openssl.
Instead, pass the full include/library paths to your compiler e.g.:
-I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib
Side note: this warning means that for other apps, you may want to use
export LDFLAGS=-L/usr/local/opt/openssl/lib
export CPPFLAGS=-I/usr/local/opt/openssl/include
Then recompile python:
brew uninstall python
brew install python --with-brewed-openssl
or for python 3
brew uninstall python3
brew install python3 --with-brewed-openssl