ConnectionFailure

Python (PyMongo)PyMongoErrorconnectivitynetworking

A connection to the MongoDB database cannot be made or was lost

What is happening?

ConnectionFailure is the base class for connection-related errors in PyMongo. It covers both initial connection failures and mid-operation connection losses. AutoReconnect is a common subclass — if you catch ConnectionFailure, you also catch AutoReconnect and NetworkTimeout.

Common causes

  1. Server unreachable or not accepting connections
  2. Connection dropped during operation (failover, network issue)
  3. Authentication failure
  4. TLS certificate validation failure
  5. Connection pool exhausted

Diagnostic Steps