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.

hi @deg - I followed your steps. located the certi SSL file by running
import certifi

And deleted the DST Root CA X3 certificate using a text editor. Still get the same issue. Any thoughts?

Hi @satejchaudhary – what was the location of the DST cert you deleted? Was it the certifi cert, or one of the local DST certs?

Hi @deg
The location was C:\Users\chaud\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.8_qbz5n2kfra8p0\LocalCache\local-packages\Python38\site-packages\certifi\cacert.pem

I am fairly new to this stuff. Would appreciate if you could elaborate on share exact steps to get to the right file. Thanks!

Hello @satejchaudhary,

I am also new on this issue and experiencing the same error. Did you get a solution for this by now?

Thank you!


The following Fix worked for me

  1. Downgraded to Python 3.8

  2. Downloaded the Lets Encrypt R3 certificate in .pem format from this website Chain of Trust - Let's Encrypt

  3. Renamed the extension from .pem to .cer . On doing so windows automatically changed the icon to look like a certificate

  4. Double Clicked on the certificate. Windows opened up a window

  5. Click on Install Certificate and the following dialogue box opens up

First install for Current User

Then for Local Machine

Hey, how do I get access to the Slack. Having this issue right now!