Connection timed out

I have a python script that connects to a database on MongoDB Atlas. Yesterday everything worked fine but today i’m working from a different location and my script can no longer make a connection to the database. this is the error: “ServerSelectionTimeoutError( pymongo.errors.ServerSelectionTimeoutError…”
I’ve found some previous posts stating the same issue, but the solution there is to whitelist the IP address. I’ve whitelisted all IP addresses (it eve says in the UI that my current IP address is included) but still the same error.
Does anybody have an idea what i could be missing?
Thanks in advance

Can you connect by shell or other tool like Compass?
Could be network related or firewall issue

I tried connecting with Compass but it also gave a connection error. that’s why i thought that the issue was the IP but i added the “” IP, so that should not be a problem, right? it is also not temporary.

Switch to another internet connection like your mobile hotspot and see if it works
May be your new location ISP not allowing/blocking the connection

On my hotspot it does seem to work so it must be related to the settings of the wifi there.
I would like to use Heroku or AWS for my script that then adds stuff to the database in the cloud.
How can i be sure that the same thing doesn’t happen there?

Hi! I don’t know if this can help you, but today we need to change all the connection strings of our containers because something (I don’t know what) changes. You can check the string connection from your Cluster page and then in the “Connect” button.

For example, for Python 3.4 or later, the connection string is:


and for Python 3.6 or later is:


Hope it helps


1 Like

Interesting. Based off this information and the fact you’re able to connect from the original location, it leads me to believe that the failure to connect might be due to a network setting/configuration from the “wifi there” location you’ve noted.

I’ve seen a few posts in the pasts regarding connectivity failures from cafe wifi’s and such in which the wifi in these particular spots did not allow outbound traffic to/from port 27017 (as one example).

The following blog post How to Deploy MongoDB on Heroku | MongoDB may be of use to you. It does have details regarding Configuring Heroku IP addresses in MongoDB Atlas as well.