Connection reset by Peer pymongo Connection reset by Peer pymongo azure azure

Connection reset by Peer pymongo


According to the information below for the issue from the pymongo api document here, the exception need to be handled manually.

exception pymongo.errors.AutoReconnect(message='', errors=None)

Raised when a connection to the database is lost and an attempt to auto-reconnect will be made.

In order to auto-reconnect you must handle this exception, recognizing that the operation which caused it has not necessarily succeeded. Future operations will attempt to open a new connection to the database (and will continue to raise this exception until the first successful connection is made).

I searched some existing solution for the issue, please see below.

  1. A code snippet from here for gracefully handling the PyMongo AutoReconnect exception.
  2. Using a middleware named MongoDBProxy to automatically handle AutoReconnect exception.

Hope it helps.