ServerSelectionTimeoutError: <CLUSTER_NAME> timed out

Im trying to connect to database with this code:

import pymongo
client = pymongo.MongoClient("mongodb+srv://<USERNAME>:<USER_PASSWORD>")

but i have ServerSelectionTimeoutError: timed out

I double checked my user password - correct
I double checked ip list (i have (includes your current IP address) and my real IP here)
And i still cant conntect to database (error on client.list_database_names() )

python version 3.10.2
pymongo version 4.1.1

Im in tilt now, i need help with it

I have the same error if i try to connect using certs:

from pymongo import MongoClient

uri = "mongodb+srv://"
client = MongoClient(uri,

db = client['testDB']
collection = db['testCol']
doc_count = collection.count_documents({})

Hi Andrey_Zubov,

Just to clarify, is the connection being attempted from the same machine that has it’s IP on the whitelist? I.e. Not a client within VM (with different network configuration(s)) running on a machine.

If so, please try performing the initial basic network connectivity tests and provide the output for the cluster you are having trouble connecting to:

  1. ping one of the hosts (prefereably the PRIMARY):
/// example
  1. telnet to one of the hosts on port 27017:
/// example
telnet 27017

Note: You can find the hostname in the metrics page of your cluster

Additionally, I would recommend to review the Troubleshoot Connection Issues documentation and verify some configurations, such as adding the client’s IP (or IP ranges) to the Network Access List. You may also find the following blog post regarding tips for atlas connectivity useful.

I would also ask if you can try connecting using mongosh or MongoDB Compass to see if the same error occurs. Please let me know the results of this.

Please note, use of the +srv connection string modifier generally automatically sets the tls (or the equivalent ssl ) option to true for the connection. You can override this behavior by explicitly setting the tls (or the equivalent ssl ) option to false with tls=false (or ssl=false ) in the query string. More info on this here.

Jason Tran