SSLCertVerificationError using python SDK

A few days ago, I created a functional python program that was successfully fetching historical data with AsyncRest in the python alpaca_trade_api SDK.

However, when trying to run the same script today, I encountered the following error for every ticker I try to get data for:

Got an error: Cannot connect to host ssl:True [SSLCertVerificationError: (1, '[SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: certificate has expired (_ssl.c:1125)')]

Manually checking the endpoint, the certificate seems fine. I tried regenerating my API key, but the problem persists. Any suggestions on how to get this working again?

1 Like

I should add that I’m using the paper trade URL. Thanks for your time.

1 Like

Seeing the same issue. Haven’t found any useful responses on how to fix.

I have installed the latest python 3.9 on my windows 10 to reproduce the problem and I experienced the same issue. I had to delete the intermediate certificate (Issued to: R3, Issued by: DST Root CA X3) from the windows CA list. It helped!

See also: Resources for Certificate Chaining Help - Let's Encrypt

1 Like

Thank you! I am back up and running. Much appreciated.

This was indeed the issue. Note that if you’re using certifi (and I was) you’ll need to delete the DST Root CA X3 certificate from the certifi SSL file.

And, final note, Windows 10 may actually reinstall the DST cert automatically. If this is happening to you, the fastest fix is to pip install certifi and modify the certifi SSL file.