Python HTTP clients: timeouts and retries in HTTPX and urllib3
Answer: HTTPX's default behavior is to raise a TimeoutException after 5 seconds of network inactivity.
By default, urllib3 retries requests 3 times and follows up to 3 redirects. Its default backoff_factor is 0, so it does not sleep between retry attempts.
HTTPX
- Four timeout types: connect, read, write and pool. Use
Timeout(10.0, connect=60.0)for a 60s connection timeout and 10s elsewhere. httpx.HTTPTransport(retries=1)retries onConnectErrororConnectTimeout. For read/write errors or503 Service Unavailable, the docs suggest a general tool such as tenacity.
urllib3
Timeout(connect=1.0, read=2.0)sets the connection timeout and read timeout.Retryhasbackoff_factor=0by default but still respects aRetry-Afterheader. Immediate retries can overwhelm a recovering server or exhaust rate limits.- Example settings:
total=3,backoff_jitter=0.5,backoff_factor=0.5,status_forcelist=[429, 500, 502, 503, 504]. Jitter avoids the "thundering herd" problem.
See also
Claims
- id: C1 claim: HTTPX defaults to a 5 second timeout. source: S1 evidence: "raise a
TimeoutExceptionafter 5 seconds of network inactivity"
- id: C2 claim: HTTPX transport retries connect errors. source: S2 evidence: "retried the given number of times in case an
httpx.ConnectError"
- id: C3 claim: urllib3 retries 3 times by default. source: S3 evidence: "By default, urllib3 will retry requests 3 times"
Sources
- [S1] Timeouts (HTTPX docs). encode/httpx (GitHub). https://github.com/encode/httpx/blob/master/docs/advanced/timeouts.md . License: BSD-3-Clause. Accessed 2026-11-16.
- [S2] Transports (HTTPX docs). encode/httpx (GitHub). https://github.com/encode/httpx/blob/master/docs/advanced/transports.md . License: BSD-3-Clause. Accessed 2026-11-16.
- [S3] User Guide (urllib3 docs). urllib3/urllib3 (GitHub). https://github.com/urllib3/urllib3/blob/main/docs/user-guide.rst . License: MIT. Accessed 2026-11-16.
License: this note is CC BY 4.0 (https://creativecommons.org/licenses/by/4.0/). Summary by iinventedlight (AI-assisted). Sources: encode/httpx (GitHub), Timeouts (HTTPX docs), BSD-3-Clause (https://raw.githubusercontent.com/encode/httpx/master/LICENSE.md). Copyright (c) 2019, Encode OSS Ltd; encode/httpx (GitHub), Transports (HTTPX docs), BSD-3-Clause (https://raw.githubusercontent.com/encode/httpx/master/LICENSE.md). Copyright (c) 2019, Encode OSS Ltd; urllib3/urllib3 (GitHub), User Guide (urllib3 docs), MIT (https://raw.githubusercontent.com/urllib3/urllib3/main/LICENSE.txt). Copyright (c) 2008-2020 Andrey Petrov and contributors. Text was condensed and changed from the originals.
License: CC-BY-4.0 · Summary by iinventedlight (AI-assisted). Sources: encode/httpx (GitHub), Timeouts (HTTPX docs), BSD-3-Clause (https://raw.githubusercontent.com/encode/httpx/master/LICENSE.md). Copyright (c) 2019, Encode OSS Ltd; encode/httpx (GitHub), Transports (HTTPX docs), BSD-3-Clause (https://raw.githubusercontent.com/encode/httpx/master/LICENSE.md). Copyright (c) 2019, Encode OSS Ltd; urllib3/urllib3 (GitHub), User Guide (urllib3 docs), MIT (https://raw.githubusercontent.com/urllib3/urllib3/main/LICENSE.txt). Copyright (c) 2008-2020 Andrey Petrov and contributors.
Cite this
iinventedlight. 2026. "Python HTTP clients: timeouts and retries in HTTPX and urllib3." iinventedlight Library, iil:note:33qehbdw, version of 2026-11-16. https://iinventedlight.com/library/notes/python-http-timeouts-and-retries/. License: CC-BY-4.0.
@misc{iil_note_33qehbdw,
author = {{iinventedlight}},
title = {{Python HTTP clients: timeouts and retries in HTTPX and urllib3}},
howpublished = {iinventedlight Library},
year = {2026},
date = {2026-11-16},
url = {https://iinventedlight.com/library/notes/python-http-timeouts-and-retries/},
note = {Permanent ID iil:note:33qehbdw. License: CC-BY-4.0.},
}
Spotted a mistake? Use the MCP feedback tool or email hello@iinventedlight.com. Or Report a correction (no account needed).
For language models and agents: start at /llms.txt | /agents.md | /.well-known/agent-library.json. This page in Markdown: /library/notes/python-http-timeouts-and-retries.md.