Hello folks,
I have a cluster to which I have no clue how to connect using Python. I want to mention right at the outset that I HAVE added my IP to the whitelist.
My cluster is a UUID based cluster: cdf46a6c-6797-40e1-a655-96b6b5291e2b
Previously when I had tried to connect to this cluster using mongo shell v4.2, I had gotten this URL to connect to from the Atlas “Connect” section, AND IT WORKS:
OLD STRING
mongo "mongodb+srv://<username>:<password>@cdf46a6c-6797-40e1-a655.35m0c.mongodb.net"
Now when I go to the Atlas interface to get my connection string, it gives me this command:
NEW STRING
mongo "mongodb+srv://<username>:<password>@cdf46a6c-6797-40e1-a655-**pri.**35m0c.mongodb.net"
Notice the extra “pri”??
In short, I’m wondering which connection string am I supposed to rely on? If I use connection string OLD STRING, both mongo shell and Python program works. If I use NEW STRING, I see the following errors:
Traceback (most recent call last):
File "mongo.py", line 40, in <module>
my_driver = initialise_mongo_client()
File "mongo.py", line 37, in initialise_mongo_client
print(client.get_database('abs_data').list_collection_names())
File "/usr/local/lib64/python3.6/site-packages/pymongo/database.py", line 880, in list_collection_names
for result in self.list_collections(session=session, **kwargs)]
File "/usr/local/lib64/python3.6/site-packages/pymongo/database.py", line 843, in list_collections
_cmd, read_pref, session)
File "/usr/local/lib64/python3.6/site-packages/pymongo/mongo_client.py", line 1515, in _retryable_read
read_pref, session, address=address)
File "/usr/local/lib64/python3.6/site-packages/pymongo/mongo_client.py", line 1346, in _select_server
server = topology.select_server(server_selector)
File "/usr/local/lib64/python3.6/site-packages/pymongo/topology.py", line 246, in select_server
address))
File "/usr/local/lib64/python3.6/site-packages/pymongo/topology.py", line 203, in select_servers
selector, server_timeout, address)
File "/usr/local/lib64/python3.6/site-packages/pymongo/topology.py", line 220, in _select_servers_loop
(self._error_message(selector), timeout, self.description))
pymongo.errors.ServerSelectionTimeoutError: cdf46a6c-6797-40e1-a655-shard-00-01-pri.35m0c.mongodb.net:27017: timed out,cdf46a6c-6797-40e1-a655-shard-00-00-pri.35m0c.mongodb.net:27017: timed out,cdf46a6c-6797-40e1-a655-shard-00-02-pri.35m0c.mongodb.net:27017: timed out, Timeout: 30s, Topology Description: <TopologyDescription id: 6234ce37bc72a6a821d90859, topology_type: ReplicaSetNoPrimary, servers: [<ServerDescription ('cdf46a6c-6797-40e1-a655-shard-00-00-pri.35m0c.mongodb.net', 27017) server_type: Unknown, rtt: None, error=NetworkTimeout('cdf46a6c-6797-40e1-a655-shard-00-00-pri.35m0c.mongodb.net:27017: timed out',)>, <ServerDescription ('cdf46a6c-6797-40e1-a655-shard-00-01-pri.35m0c.mongodb.net', 27017) server_type: Unknown, rtt: None, error=NetworkTimeout('cdf46a6c-6797-40e1-a655-shard-00-01-pri.35m0c.mongodb.net:27017: timed out',)>, <ServerDescription ('cdf46a6c-6797-40e1-a655-shard-00-02-pri.35m0c.mongodb.net', 27017) server_type: Unknown, rtt: None, error=NetworkTimeout('cdf46a6c-6797-40e1-a655-shard-00-02-pri.35m0c.mongodb.net:27017: timed out',)>]>
Somebody please help!