Before anything, if you have updated OSx recently, run from command line

xcode-select --install
brew doctor
brew update
brew upgrade


brew install openssl1.1, but only few python versions have openssl1.1 others while others have OpenSSL 1.0.2 according to this post []

OpenSSL 1.1.0 support in the ssl module was only added to Python 2.7.13, 3.5.3 and 3.6.0 …

If you want to compile any other python version, then you have to download and compile OpenSSL 1.0.2 and manually link it [] and later remove it.