ServerSelectionTimeoutError when working with cloud MongoDB Instance

My cloud MongoDB setup was working fine at first but randomly without me making any changes to my codebase or db set up I started getting a ServerSelectionTimeoutError and connection closed error when trying to run my python application from localhost against my cloud mongoDB instance.

Everything runs fine again my local mongoDB setup but I keep getting this error when trying to run my server again my cloud DB instance.

please let me know if you have any ideas on a workaround for this issue?

This could be a network access issue. Did you configure Atlas to allow access from your IP? If not follow the instructions here:

If you’ve already done these steps perhaps your IP has changed? Try double checking the IP access rules for your cluster.

Another way to confirm would be to attempt to connect via the mongo shell from the same machine. If both mongosh and pymongo cannot connect that’s a clear indication of a network issue.

I have allowed access to all IP addresses on my atlas account and I was able to connect via the mongo shell from the same machine.

It looks like I only get this issue when I am trying to connect using python.

Here is the python code I use to connect to my cloud DB

You have to remove tls=False. Atlas requires TLS.

1 Like

This topic was automatically closed 5 days after the last reply. New replies are no longer allowed.