ServerSelectionTimeoutError - pymongo4.5

Hi Mongodb community.

I am facing the following error on my app which uses pymongo 4.5.

ServerSelectionTimeoutError
No replica set members found yet, Timeout: 30s, Topology Description: <TopologyDescription id: 64ef55b92030ab4b7a836e07, topology_type: ReplicaSetNoPrimary, servers: [<ServerDescription ('cluster0-shard-00-00.if2rk.mongodb.net', 27017) server_type: Unknown, rtt: None>, <ServerDescription ('cluster0-shard-00-01.if2rk.mongodb.net', 27017) server_type: Unknown, rtt: None>, <ServerDescription ('cluster0-shard-00-02.if2rk.mongodb.net', 27017) server_type: Unknown, rtt: None>]>

The strange thing is this happens only sometimes, not always. Like about 1% among total tries.

This is my connection string.

mongodb+srv://{MONGO_DB_USER}:{MONGO_DB_PASSWORD}@{MONGO_DB_HOST}/{MONGO_DB_DATABASE}?retryWrites=true&w=majority&replicaSet={MONGO_DB_REPLICA_SET}&readPreference=PrimaryPreferred

Thanks in advance!

Hey @Alphanomics_LLC,

Welcome to the MongoDB Community!

Could you share how frequently you are encountering the ServerSelectionTimeoutError issue? Is it occurring a few times within a day or perhaps once a week?

Also, please 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.

Please note, the 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. For more info, please refer here.

Regards,
Kushagra