I keep getting the error below due to issues with connecting to my mongodb database via a bash console on pythonanywhere:
pymongo.errors.ServerSelectionTimeoutError: lanfrica-shard-00-01.oap4d.mongodb.net:27017: timed out (configured timeouts: socketTimeoutMS: 20000.0ms, connectTimeoutMS: 20000.0ms),lanfrica-shard-00-00.oap4d.mongo
db.net:27017: timed out (configured timeouts: socketTimeoutMS: 20000.0ms, connectTimeoutMS: 20000.0ms),lanfrica-shard-00-02.oap4d.mongodb.net:27017: timed out (configured timeouts: socketTimeoutMS: 20000.0ms, co
nnectTimeoutMS: 20000.0ms), Timeout: 30s, Topology Description: <TopologyDescription id: 67fe89198a05fbf674e3bae9, topology_type: ReplicaSetNoPrimary, servers: [<ServerDescription ('lanfrica-shard-00-00.oap4d.mo
ngodb.net', 27017) server_type: Unknown, rtt: None, error=NetworkTimeout('lanfrica-shard-00-00.oap4d.mongodb.net:27017: timed out (configured timeouts: socketTimeoutMS: 20000.0ms, connectTimeoutMS: 20000.0ms)')>
, <ServerDescription ('lanfrica-shard-00-01.oap4d.mongodb.net', 27017) server_type: Unknown, rtt: None, error=NetworkTimeout('lanfrica-shard-00-01.oap4d.mongodb.net:27017: timed out (configured timeouts: socketT
imeoutMS: 20000.0ms, connectTimeoutMS: 20000.0ms)')>, <ServerDescription ('lanfrica-shard-00-02.oap4d.mongodb.net', 27017) server_type: Unknown, rtt: None, error=NetworkTimeout('lanfrica-shard-00-02.oap4d.mongod
b.net:27017: timed out (configured timeouts: socketTimeoutMS: 20000.0ms, connectTimeoutMS: 20000.0ms)')>]>
I have added the IPs of the bash console to mongodb network access, but it still doesn't work. This usually solves the issue for me in other environments (like on my PC, on another virtual server, etc). Some things I want to confirm:
- is the IP on the bash console dynamic?
- does pythonanywhere have strict network access rules where some ports ae restricted? Since MongoDB Atlas uses port 27017 by default (even when accessed via the SRV connection string), I am concerned that my connection attempts are likely being blocked by PythonAnywhere’s firewall.