python network_error ai_generated true

TimeoutError: [Errno 110] Connection timed out

ID: python/timeouterror

Also available as: JSON · Markdown
80%Fix Rate
82%Confidence
50Evidence
2023-01-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
311 active

Root Cause

Network connection or operation timed out.

generic

Workarounds

  1. 90% success Add retry with exponential backoff for transient failures
    import tenacity
    
    @tenacity.retry(wait=tenacity.wait_exponential(multiplier=1, max=60), stop=tenacity.stop_after_attempt(5))
    def fetch_with_retry(url):
        return urllib.request.urlopen(url, timeout=10).read()

    Sources: https://docs.python.org/3/library/urllib.request.html

  2. 88% success Verify target host is reachable: DNS, firewall, port
    DNS, firewall, port

    Sources: https://docs.python.org/3/library/socket.html#socket.create_connection

Dead Ends

Common approaches that don't work:

  1. Increase timeout to very large value 65% fail

    Just delays the failure, doesn't fix the network issue

  2. Remove timeout entirely 85% fail

    Process hangs forever on unreachable hosts

Error Chain

Frequently confused with: