[Fixed]-Pymongo [SSL: CERTIFICATE_VERIFY_FAILED]: certificate has expired on Mongo Atlas

16👍

This is because of a root CA Let’s Encrypt uses (and Mongo Atals uses Let’s Encrypt) has expired on 2020-09-30 – namely the "IdentTrust DST Root CA X3" one.

The fix is to manually install in the Windows certificate store the "ISRG Root X1" and "ISRG Root X2" root certificates, and the "Let’s Encrypt R3" intermediate one – link to their official site – https://letsencrypt.org/certificates/

Copy from the comments: download the .der field from the 1st category, download, double click and follow the wizard to install it.

13👍

I solved the problem on my windows machine. It had to do with the expiring DST Root CA X3 certificate from Let’s Encrypt.

  1. Download https://letsencrypt.org/certs/lets-encrypt-r3.pem
  2. rename file .pem to .cer
  3. double click and install
  4. Restart your PC

Still, if it doesn’t work

  1. Go to https://letsencrypt.org/certificates/
  2. Download ISRG Root X1, ISRG Root X2 ( Root Certificates), Let’s Encrypt R3 ( Intermediate Certificates)
  3. Restart your PC

5👍

I found the solution in the mongoDB community. Download https://letsencrypt.org/certs/lets-encrypt-r3.pem

  1. rename the .pem file to .cer
  2. double-click and install
  3. try to run the app

Your SSL issue should be resolved.

source: https://www.mongodb.com/community/forums/t/keep-getting-serverselectiontimeouterror/126190/13

0👍

Another solution from MongoDB community. Super easy and worked for me. You can read the full solution here –

https://www.mongodb.com/community/forums/t/keep-getting-serverselectiontimeouterror/126190/

Here is what worked for me (Windows 11) –

heck that dnspython, pymongo and certifi are installed in your virtual environment or install them by:

pip install dnspython pymongo certifi

Can you use the terminal/command line and run Python, in the Python environment can you enter and = run the following commands (please change the password as appropriate for your user in your Atlas cluster):

from pymongo import MongoClient
import certifi
s = MongoClient("mongodb+srv://m220student:m220password@cluster0.maiqr.mongodb.net", tlsCAFile=certifi.where())

Leave a comment