Forums

( Paid account) Trying to connect to mongo db through atlas, connection refused as connection url is changed to local host

I am attempting to connect to my database on MongoDB through atlas. From what i have done so far the connection string is being read correctly from my .env file, the ip for pythonanywhere is already white listed in Mongo Atlas and I am using a paid account. But i keep getting connection refused on the basis that the mongo client is trying to connect to local host instead of the connection url I provided. The following is the first part of the error message

Error running WSGI application.   2024-08-01 18:34:55,504: pymongo.errors.ServerSelectionTimeoutError: localhost:27017: [Errno 111] Connection refused (configured timeouts: socketTimeoutMS: 30000.0ms, connectTimeoutMS: 30000.0ms), Timeout: 30s, Topology Description: <TopologyDescription id: 66abd530699bfa9a03047074, topology_type: Unknown, servers: [<ServerDescription ('localhost', 27017) server_type: Unknown, rtt: None, error=AutoReconnect('localhost:27017: [Errno 111] Connection refused (configured timeouts: socketTimeoutMS: 30000.0ms, connectTimeoutMS: 30000.0ms)')>]>.    
2024-08-01 18:34:55,504:   File "/var/www/synthex2020_pythonanywhere_com_wsgi.py", line 27, in <module>
2024-08-01 18:34:55,505:     from main import app as application  # noqa
2024-08-01 18:34:55,505: 
2024-08-01 18:34:55,505:   File "/home/synthex2020/synthex2020.pythonanywhere.com/main.py", line 17, in <module>

I'd suggest adding some logging to make sure your code uses the settings you expect it to use.