TimeoutError
Error message
TimeoutError: [Errno 110] Connection timed out
Quick summary
A network or I/O operation exceeded its time limit and was terminated.
Why this happens
Server is slow to respond
Network latency is too high
Deadlock or infinite loop in the operation
Timeout value is set too low
Minimal example
✗ Broken code
import urllib.request
url = 'https://slow-server.com'
response = urllib.request.urlopen(url) # TimeoutError if server is too slow✓ Fixed code
import urllib.request
try:
response = urllib.request.urlopen(url, timeout=10)
except TimeoutError:
print("Request timed out — server may be slow or down")Set an explicit timeout and catch TimeoutError to handle slow or unresponsive servers.
How to diagnose
Check if the server is responding slowly
Verify the timeout value is reasonable
Test the operation with a longer timeout
How to fix
Increase the timeout value
Implement retry logic with backoff
Use try/except TimeoutError to handle timeouts
Optimize the operation to complete faster
How to prevent
Set appropriate timeout values for all network operations
Implement retry with exponential backoff
Monitor response times and adjust timeouts
Related Resources
Related Lessons
- Exceptions
Timeout handling.