Pymongo ServerSelectionTimeoutError

Hi guys, I’m trying to connect to my mongo atlas from my machine, but I’m getting a serverSelectionTimeoutError, i have added my IP address to he access list still doesn’t work, but strangely if allow access from all origin, it connects successfully, I’m clueless as it stands, and would appreciate any help/pointers.

pymongo.errors.ServerSelectionTimeoutError: cluster0-shard-00-00.mghyr.mongodb.net:27017: timed out,cluster0-shard-00-02.mghyr.mongodb.net:27017: timed out,cluster0-shard-00-01.mghyr.mongodb.net:27017: timed out, Timeout: 30s, Topology Description: , , ]>

I’m Using the motor AsyncIOMotorClient driver in my FastApi app, happy to provide more info if needed

can you connect from terminal with mongo or mongosh, and with Compass, without a problem?

2 Likes

Hi, Thanks for your response, I am unable to connect with compass when i tried, got this error connect ETIMEDOUT 52.49.220.55:27017, haven’t tried with mongosh.

if even Compass gives time out error, then others will do the same. this also means the problem you are having is not related to pymongo, or to similar drivers.

although it is pretty simple to do, you need to check the way you set the IP access list. you may have set a short duration and forgot about it.

also, check if you are on a shared network and someone resets your router so it gets another IP after you set one in the access list.

2 Likes

HI, thanks again for your response, so I fixed the access list and now I can connect from compass, apparently the security group was causing the issue, I changed it for my ip and it works, but my hosted machine still cannot connect

it is possible your “hosted” machine might be using some other IP. can you give more details about it? the difference between the pc you used Compass and the system your app runs!?

if it is on some cloud provider, then the IP it has will surely be different. or if you use some complex network settings so that the app is in a virtual machine having its own external IP address, then you will also have to add its own IP.

1 Like

Hi, Thanks alot for your responses, finally fixed it, i was actually connecting via vpc, i didn’t set my route table properly.

Hi again… so aparrently i solved that isusue but this one just popped up, something about ReplicaSetNoPrimary, i’m going to create a new topic, just wanted to pin it here too, any help will be appreciated.

description: “cluster0-shard-00-01-pri.mghyr.mongodb.net:27017: timed out,cluster0-shard-00-00-pri.mghyr.mongodb.net:27017: timed out,cluster0-shard-00-02-pri.mghyr.mongodb.net:27017: timed out, Timeout: 30s, Topology Description: <TopologyDescription id: 62f0df03e2be3642332186bb, topology_type: ReplicaSetNoPrimary, servers: [<ServerDescription (‘cluster0-shard-00-00-pri.mghyr.mongodb.net’, 27017) server_type: Unknown, rtt: None, error=NetworkTimeout(‘cluster0-shard-00-00-pri.mghyr.mongodb.net:27017: timed out’)>, <ServerDescription (‘cluster0-shard-00-01-pri.mghyr.mongodb.net’, 27017) server_type: Unknown, rtt: None, error=NetworkTimeout(‘cluster0-shard-00-01-pri.mghyr.mongodb.net:27017: timed out’)>, <ServerDescription (‘cluster0-shard-00-02-pri.mghyr.mongodb.net’, 27017) server_type: Unknown, rtt: None, error=NetworkTimeout(‘cluster0-shard-00-02-pri.mghyr.mongodb.net:27017: timed out’)>]>”