when im try to connect with my home pc its work fine! im trying to connect in pythonanywhere to atlas mongo cloud with pymongo but im keep getting this error
"pymongo.errors.ServerSelectionTimeoutError: cluster0-shard-00-01-spxa1.mongodb.net:27017: [Errno 111] Connection refused,cluster0-shard-00-02-spxa1.mongodb.ne t:27017: [Errno 111] Connection refused,cluster0-shard-00-00-spxa1.mongodb.net:27017: [Errno 111] Connection refused"
my code:
import pymongo
def Func(database_name,collection_name):
""" connect to mongodb and return database and collection"""
## ---- connect to mongo & create or switch databse ---- ##
mongo = pymongo.MongoClient("mongodb+srv://<user>:<password>@cluster0-spxa1.mongodb.net/test?retryWrites=true&w=majority")
database = mongo[database_name]
## ---- return collection ---- ##
return database[collection_name]
Func("test","test").insert_one({"test":"1"})