Resolving the mongodb atlas hostname to an IP address

Hi :blush:

I’m working with MongoDB Compass and MongoDB Atlas.
I’m trying to connect to my Mongo database but I’m facing this error:

ValueError: Error connecting to MongoDB -- [Errno -5] No address associated with hostname, Timeout: 5.0s

I think the there’s a problem resolving the hostname
to an IP address.

Probably not. The error message seems to indicate that you are not using the cluster address correctly. What is the connection string that you are using?

A cluster has no IP address. A cluster is a group of hosts. The SRV and TXT DNS records of the cluster resolves to hosts. In your case it is:

id 64218
opcode QUERY
flags QR RD RA
;ANSWER 60 IN TXT "authSource=admin&replicaSet=atlas-frynfj-shard-0" 60 IN SRV 0 0 27017 60 IN SRV 0 0 27017 60 IN SRV 0 0 27017


That works fine from here. Make sure you change your password now. Share a screenshot that shows how you use the connection string.


When i use it in MongoDB Compass it works totally fine and it shows my databases.
But when i use it in my python script and try to connect to my Mongo database i got the error above: No address associated with hostname

I don’t know if this would help or not but when i try to ping to the hostname i got :
No address associated with host name

As mentioned before

Not a host name, means not a host, means no IP address, means not ping-able. However you may ping any of the 3 hosts refered in the SRV records I shared before.

2 things could explain why it does not work in your python.

1 - may be python does not like the double quotes around the connection string

2 - you might be missing a module that knows how resolve SRV records

Given that it works in Compass DNS resolution of the SRV records from your host works.

So it could be point 2 of @steevej’s reply or some other environment issue. Can you try with a clean pyvenv and install the driver there?

What driver and version is being used?