Python – Fix SSL Certificate Verified Failed

ERROR
Retrying (Retry(total=4, connect=None, read=None, redirect=None, status=None)) after connection broken by ‘SSLError(SSLCertVerificationError(1, ‘[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: self signed certificate in certificate chain (_ssl.c:1076)’))’: /simple/prettytable/

FIX

pip install --trusted-host pypi.org --trusted-host files.pythonhosted.org prettytable

or

pip install --trusted-host pypi.python.org --trusted-host files.pythonhosted.org --trusted-host pypi.org prettytable

Change “prettytable” to whatever you’re trying to install.  Also note the first command works for me every time but if it doesn’t for you, try the second command.

EXPLAINATION

The error message you see is related to SSL certificate verification when the Python package manager, pip, tries to download a package from the Python Package Index (PyPI).

In this case, it’s failing to download the prettytable package because the certificate presented by the server (or an intermediary such as a proxy) is self-signed, and Python can’t verify it. SSL Offloading was the root cause of this, which many companies do.