pymongo.errors.ServerSelectionTimeoutError with atlas even when added to network access

Hi, Make sure you entered the user password, not the MongoDB account password. I encountered similar issue.

1 Like

I’m having the same issue. Is there no solution for this? I tried to do what @shane told and got the same results as @sadru.

This thread is 2 months old.

Please start a new thread and post a screenshot of what you are trying that shows the issue you are having.

If you could not resolve your issue with what was posted in this thread, then your issue is slightly different and should be on its own thread.

I am going through the same problem recently. Did you get any solution to this issue?

1 Like

As already mentioned

Now 3 months, and more since the original message.

As already mentioned

As already mentioned

Hello, buddy.
I had this problem before, so i have tried everything to solve it and i did.
So, most probably you added your own ip adress when you were creating a db, but you need to allow all the ip adresses that will connect to your db.
You may change it in your page in network access.
Thank you for attention! :slightly_smiling_face:
I hope it will be useful for you.

21 Likes

Couldn’t connect with enabled VPN (ProtonVPN). Works without it.

1 Like

@sadru Go to Mongo db atlas dashboard
Select your current project
click on Network Access (left side menu)
In the “IP Access List” tab
Make sure you don’t have an old dynamic IP of your machine set there
Or you can add 0.0.0.0/0 (includes your current IP address) to access from anywhere

7 Likes

This worked for me, thanks you so much

1 Like

You’re the most generous Lord in all the Land, thank you sir :slightly_smiling_face:

Thx bro you are a truly god

Another solution-
I created a SCRAM user in the database access tab.
Then, I added &authSource=the_database&authMechanism=SCRAM-SHA-1 to the connection string. Like this:

connect_string = 'mongodb+srv://{}:{}@{}/?retryWrites=true&authSource=the_database&authMechanism=SCRAM-SHA-1'.format(username, password, hostname)
py_client = MongoClient(connect_string)

I asked a team member in chat and they gave a working answer!

This is what they said:
If you are receiving an SSL certificate error when connecting to your Atlas cluster with PyMongo, such as:

  • unable to get local issuer certificate
  • [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed

This indicates that Python does not have access to the system’s root certificates.

This often occurs because OpenSSL does not have access to the system’s root certificates or the certificates are out of date. Linux users should ensure that they have the latest root certificate updates installed from their Linux vendor.

A sample command script is included in “/Applications/Python <version_number>” to install a curated bundle of default root certificates from the third-party certifi package. Open a terminal window and run the following command, with your Python version.

open "/Applications/Python <version_number>/Install certificates.command"

Alternatively, you can head to the Applications folder in Finder and double click “Install Certificates.command” to run the script:

6 Likes

I logged in to thanks you very much :slight_smile:

Not sure how special it is but for me it works by replacing the url with mongodb+srv://:@cluster0.gr4blbt.mongodb.net/?ssl=true&ssl_cert_reqs=CERT_NONE&retryWrites=true&w=majority

Basically adding ssl=true&ssl_cert_reqs=CERT_NONE and remove the “?” in the end

ssl_cert_reqs=CERT_NONE is insecure and not recommended. See ServerSelectionTimeoutError [SSL: CERTIFICATE_VERIFY_FAILED] Trying to understand the origin of the problem for how to fix TLS errors securely.

2 Likes


I am facing this issue can anyone help me out

Having this same issue but all of the suggested fixes haven’t worked. The annoying part is that I was able to connect to my database a few weeks ago but now it doesn’t work. Very frustrating, not sure what could have changed.

Edit: I removed “?retryWrites=true&w=majority’” from the end of my uri and it started working… not sure why that worked but oh well.

This answer helped me to solve the problem, thank you.

1 Like