---
source: https://iinventedlight.com/library/notes/python-http-timeouts-and-retries.md
title: "Python HTTP clients: timeouts and retries in HTTPX and urllib3"
license: CC-BY-4.0
license_url: https://creativecommons.org/licenses/by/4.0/
source_license: "BSD-3-Clause (encode/httpx (GitHub)); BSD-3-Clause (encode/httpx (GitHub)); MIT (urllib3/urllib3 (GitHub)); prose restates cited source lines in own words"
license_family: mixed-green
attribution: "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."
author: "iinventedlight (synthesis of cited sources); text drafted with AI assistance"
date: 2026-11-16
status: published
approved_by: "Cole Withington, 2026-11-20 13:14 PT: \"Publish the full batch and rewrite the 6 live notes\""
checked_on: 2026-11-16
as_of: 2026-11-16
confidence: medium
untested: "Not reproduced (2026-11-16). Docs read; no API call was made for this note."
category: coding-references
topic_area: "code-python: testing and HTTP"
tags: [python, httpx, urllib3, timeouts, retries, backoff]
client: Librarian
sources:
  - id: S1
    title: "Timeouts (HTTPX docs)"
    publisher: encode/httpx (GitHub)
    url: https://github.com/encode/httpx/blob/master/docs/advanced/timeouts.md
    accessed: 2026-11-16
    license: "BSD-3-Clause"
  - id: S2
    title: "Transports (HTTPX docs)"
    publisher: encode/httpx (GitHub)
    url: https://github.com/encode/httpx/blob/master/docs/advanced/transports.md
    accessed: 2026-11-16
    license: "BSD-3-Clause"
  - id: S3
    title: "User Guide (urllib3 docs)"
    publisher: urllib3/urllib3 (GitHub)
    url: https://github.com/urllib3/urllib3/blob/main/docs/user-guide.rst
    accessed: 2026-11-16
    license: "MIT"
---
# 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 on `ConnectError` or `ConnectTimeout`. For read/write errors or `503 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.
- `Retry` has `backoff_factor=0` by default but still respects a `Retry-After` header. 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

- [ao-retries-exponential-backoff](https://iinventedlight.com/library/notes/ao-retries-exponential-backoff/)
- [ao-retries-sdk-defaults](https://iinventedlight.com/library/notes/ao-retries-sdk-defaults/)
- [ao-structured-instructor-validation-retries](https://iinventedlight.com/library/notes/ao-structured-instructor-validation-retries/)

## Claims

- id: C1
  claim: HTTPX defaults to a 5 second timeout.
  source: S1
  evidence: "raise a `TimeoutException` after 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.

---

Agents: [/agents.md](/agents.md) | [/.well-known/agent-library.json](/.well-known/agent-library.json).
