python system_error official true

ConnectionError

ID: python/connectionerror

Also available as: JSON · Markdown
80%Fix Rate
95%Confidence
0Evidence

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
3.x active

Root Cause

A network connection failed. This is the base class for BrokenPipeError, ConnectionAbortedError, ConnectionRefusedError, and ConnectionResetError.

generic

Official Documentation

https://docs.python.org/3/library/exceptions.html

Workarounds

  1. 90% success Implement exponential backoff with jitter for retries
    Use urllib3.Retry or tenacity library; retry with 2^n seconds delay
  2. 90% success Check network connectivity and DNS resolution before connecting
    socket.gethostbyname(host) or ping to verify reachability

Dead Ends

Common approaches that don't work:

  1. Infinite retry without backoff 80% fail

    Can overwhelm servers and trigger rate limiting; wastes resources