I can connect to the Mongo server just fine when running it on my shell using mongosh. But when I try to connect to the server using pymongo it gives me the following error. [Errno 54] Connection reset by peer (configured timeouts: connectTimeoutMS: 20000.0ms). I am running pymongo 4.6.1 and python 3.8/3.10. And pymongo does not have the C extentsions.
If anyone could help me solve this issue I would greatly appreciate it.
I’m the same and it works for me … Can you post some code (obscuring your password and system name of course) @Carolina_Martin ?
If possible, cut-and-paste the invocation and the output.
This is what I am using to connect to MongoDB. I had previously had tls = false and once I removed it I can now connect locally to the mongo server. However I still get an error when it tries to connect with pythonanywhere. This is the code I use to connect to mongo.
def connect_db():
if client is None:
print("Setting client because it is None.")
if os.environ.get("CLOUD_MONGO", LOCAL) == CLOUD:
password = os.environ.get("MONGODB_PASSWORD")
if not password:
raise ValueError('You must set your password '
+ 'to use Mongo in the cloud.')
print("Connecting to Mongo in the cloud.")
client = pm.MongoClient(f'mongodb+srv://{user}:{password}'
+ '@{databasename}.{}.mongodb.net'
+ '/?retryWrites=true&w='
+ 'majority')
else:
print("Connecting to Mongo locally.")
client = pm.MongoClient()
And I get this error when running in pythonanywhere: