What is your Python version and OS?
This error means that your Python app fails to load CA certificate that signed the certificate of the server.
There are two cases:
The website is signed by an unknown CA. Then you need to get the certificate of that CA and install to your system. To test this issue try to connect with your app to a well known site. E.g. stackoverflow.com
. If it works, then system certificates are loaded, and only the certificate of the server's CA is missing.
If your app can't verify the certificates of well know apps, it means that it loaded no CA certificates at startup. You should load them manually.
To load CA certificates in Python use SSLContext.load_verify_locations
method.
UPDATE
Root of all evil
Open the site https://www.cryptodatadownload.com/
in Firefox. And enjoy the security threat page with the core reason Error code: SEC_ERROR_UNKNOWN_ISSUER
The problem is that this site's certificate is signed by GeoTrust RSA certificate, that is not included in Mozilla CA Store. Why Mozilla? Because it's CA certificate store is used by many open source projects.
An extra layer of complexity: since Python 3.8 it no longer uses certificates from Mac OS. You need to load CA certificates manually.
Solution
The simplest way is to extract the CA certificates for the target site using browser and load them in urlopen
call or SSL context construction.
Here is the file with the CA certificate chain for https://www.cryptodatadownload.com/
. I built it using Chrome on Windows.
Save it under name geotrust.cer
and try the following snippet:
import urllib.request as request
request.urlopen("https://www.cryptodatadownload.com/", cafile="geotrust.cer")
On my python 3.6 it works fine.
More tricky path is to add those two certificates to the CA path of your Python installation, but it is VERY platform dependent. I can't tell you a receipt for Mac OS