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 -- pfe.ggfaafp.mongodb.net:27017: [Errno -5] No address associated with hostname, Timeout: 5.0s

I think the there’s a problem resolving the hostname pfe.ggfaafp.mongodb.net
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
rcode NOERROR
flags QR RD RA
;QUESTION
pfe.ggfaafp.mongodb.net. IN ANY
;ANSWER
pfe.ggfaafp.mongodb.net. 60 IN TXT "authSource=admin&replicaSet=atlas-frynfj-shard-0"
pfe.ggfaafp.mongodb.net. 60 IN SRV 0 0 27017 ac-85mukat-shard-00-00.ggfaafp.mongodb.net.
pfe.ggfaafp.mongodb.net. 60 IN SRV 0 0 27017 ac-85mukat-shard-00-01.ggfaafp.mongodb.net.
pfe.ggfaafp.mongodb.net. 60 IN SRV 0 0 27017 ac-85mukat-shard-00-02.ggfaafp.mongodb.net.
;AUTHORITY
;ADDITIONAL

this:
mongodb+srv://config:mounapfe@pfe.ggfaafp.mongodb.net/

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

image

Well,
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?