Unable to connect from pymongo to Atlas using Compass URI

I am trying to connect to my Atlas cluster using python/pymongo on my Windows 10 PC. I am using the same uri (excluding +srv) that Compass on my PC uses to connect to the cluster but I am getting [Errno 11001] getaddrinfo failed. Code snippet follows:

uri = “mongodb://m220-student:m220-pwd@m220.c3djr.mongodb.net/test?authSource=admin&replicaSet=atlas-13r6jd-shard-0”
dbproc = MongoClient(uri)

Any help would be greatly appreciated.

1 Like

Why

You should use the same URI. The address m220.c3djr.mongodb.net is the address of a replica set cluster.

1 Like

I am using the same UIR but dropped off the +srv because it requires another module that I have not installed

1 Like

Well, actually mongodb://… and mongodb+srv://… are 2 very different URI even if you use the same string for the dot dot dot part.

The module that you have not install maps the mongodb+srv into its mongodb counter part.

You have 2 choices:

  1. Install the module that is required
    –or–
  2. Go into Atlas and obtain the non-SRV connection string of your cluster.

The latter will contains 3 host addresses that looks like m220-shard-99-99-c3djr.mongodb.net.

1 Like

Thanks very much. I thought the +srv just created a secure connection. I have installed dnspython and it now works.

1 Like

For more information you may want to look at:

1 Like

I had read that once before but my interpretation was that I would need to create that srv entry on my PC, which I have not done. If you don’t mind, what am I not understanding?

1 Like

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