A requests.get() call with no timeout can wait forever. That isn’t an exaggeration of a rare edge case; it’s the library’s documented default, and it’s why scripts that poll an API overnight sometimes freeze without an error. Retries have their own surprise. The standard retry helper won’t retry a POST at all unless told to, and its backoff doesn’t start where most people expect. A small local server that fails on purpose, slows down on purpose and sends rate-limit headers on purpose shows exactly what each setting does, with the timings it produced.
Timeouts first
There is no default
The Requests documentation’s advanced usage guide states that by default, requests do not time out unless a timeout value is set explicitly, and warns that without one, code may hang for minutes or more. Every call to an outside server should carry one.
Connect and read are different clocks
The same guide splits a timeout into two parts. The connect timeout covers establishing the connection to the remote machine. The read timeout is how long the client waits for the server to send a response, specifically the time between bytes, which in nearly every case means the wait for the first byte. A single number sets both. A tuple sets them separately, and the docs’ example uses timeout=(3.05, 27), explaining that connect timeouts work best slightly above a multiple of 3 seconds, the default TCP packet retransmission window.
Measured
The test server had an endpoint that waited five seconds before answering. With a read timeout of one second:
requests.get("http://127.0.0.1:8767/slow", timeout=(3.05, 1.0))
# raised ReadTimeout after 1.0 sThe read timeout is not a total deadline
Because the read timeout measures the gap between bytes, a slow but steady server never trips it. A second test server, written with raw sockets, sent its response headers at once and then a six-byte body one byte every 0.9 seconds. With the same timeout=(3.05, 1.0), the call didn’t fail. It returned abcdef after 5.43 seconds, more than five times the “timeout.” For a hard limit on total time, the call needs an outside deadline, such as running it in a thread or task with its own timer, or streaming the body with stream=True and checking the elapsed time while reading chunks.
Why the defaults exist
Leaving timeouts off by default lets long downloads and slow but legitimate APIs work without configuration, which is a reasonable choice for a general-purpose library. It moves the decision to the caller. A script that talks to one internal service on a home network can pick a short timeout and fail fast. A tool that downloads large files over a slow link needs a generous read timeout and a separate check on total time. Neither choice fits the other’s job, which is why the library leaves it open.

Adding retries
The adapter pattern
Requests delegates retries to the urllib3 library underneath it. The usual setup mounts an HTTPAdapter with a Retry policy on a session:
import requests
from requests.adapters import HTTPAdapter
from urllib3.util.retry import Retry
retry = Retry(
total=5,
backoff_factor=0.5,
status_forcelist=[429, 500, 502, 503, 504],
)
session = requests.Session()
session.mount("https://", HTTPAdapter(max_retries=retry))
session.mount("http://", HTTPAdapter(max_retries=retry))What each setting means
urllib3’s Retry reference defines status_forcelist as the set of HTTP status codes that should force a retry, and notes a retry only happens when the method is also in allowed_methods. backoff_factor controls how long to sleep between attempts and is zero, meaning no backoff, by default. respect_retry_after_header is on by default for the status codes in RETRY_AFTER_STATUS_CODES, which the docs list as 413, 429 and 503. The maximum backoff defaults to 120 seconds.
Backoff, measured
A server that fails three times
The test endpoint returned 503 Service Unavailable for its first three requests and 200 after that. With the policy above, using urllib3 2.8.0:
| Result | Value |
|---|---|
| Final status | 200, body ok |
Retries recorded in resp.raw.retries.history |
3, each a 503 |
| Total time | 3.04 s |
Where the three seconds went
The docs describe the backoff factor as applying between attempts after the second try. Reading Retry.get_backoff_time() in the installed version confirms it: the sleep is zero when there has been only one consecutive error, and backoff_factor × 2^(n−1) after that, capped at the maximum. With a factor of 0.5, that’s no wait before the first retry, 1.0 second before the second and 2.0 before the third, 3.0 seconds in all, matching the 3.04 measured. Larger factors grow fast: a factor of 2 with five retries would sleep 0 + 4 + 8 + 16 + 32 seconds, a full minute.
Retry-After wins
A second endpoint always answered 429 Too Many Requests with a Retry-After: 2 header. A policy of two retries with a tiny backoff factor of 0.1 still took 4.01 seconds before giving up with RetryError, because urllib3 waited the server’s requested two seconds before each retry instead of its own tenth of a second. That’s the polite behavior, and the reason not to turn respect_retry_after_header off when talking to rate-limited APIs.
Spreading retries out
When many clients fail at the same moment, say every device in a house losing the same cloud service, identical backoff schedules make them all retry at the same instants. The installed Retry class accepts a backoff_jitter parameter, and its backoff code adds a random amount up to that value to each sleep. A small jitter, a fraction of a second to a second, breaks up the synchronized waves without changing the overall schedule much.

The POST surprise
Default methods
The urllib3 docs say it only retries methods considered idempotent, ones where repeating the request ends in the same state. The default list, printed from the library itself, is DELETE, GET, HEAD, OPTIONS, PUT and TRACE. POST and PATCH are missing.
Measured
| Policy | POST to the endpoint that fails three times |
|---|---|
Default allowed_methods |
503, 0 retries |
allowed_methods=None |
200 after 3 retries |
With the default policy, a POST to a flaky endpoint fails immediately, even with status_forcelist set. Passing allowed_methods=None makes urllib3 retry any method, which worked in the test but carries a real risk: if the server processed the first POST and only the response was lost, a retry can create a second order, a second payment or a second message. Retrying POST is safe only when the API supports an idempotency key or the operation is harmless to repeat.
Plain requests with no policy
No retries at all
Without a mounted adapter, requests.get() on the failing endpoint simply returned the 503, with no retry. Requests returns HTTP error codes as normal responses rather than exceptions, so code has to check response.status_code or call response.raise_for_status(), or a 503 page gets treated as data.
A compact helper
def make_session(retries=5, backoff=0.5):
retry = Retry(total=retries, backoff_factor=backoff,
status_forcelist=[429, 500, 502, 503, 504])
s = requests.Session()
adapter = HTTPAdapter(max_retries=retry)
s.mount("https://", adapter)
s.mount("http://", adapter)
return s
s = make_session()
r = s.get(url, timeout=(3.05, 10))
r.raise_for_status()The timeout still has to be passed on every call. The session doesn’t remember one.
Seeing retries happen
Retries are silent by default, which makes a slow script hard to diagnose. Turning on debug logging for urllib3 exposes each attempt:
import logging
logging.basicConfig(level=logging.DEBUG)Against the failing endpoint, the log showed a line for each GET /flaky with its 503 status, followed by Incremented Retry for (url='/flaky'): Retry(total=4, ...) and then Retry: /flaky before the next attempt. The total counter in that line counts down with each retry, so the log also shows how much budget is left. Setting the level for just the urllib3 logger, with logging.getLogger("urllib3").setLevel(logging.DEBUG), keeps the rest of an application’s logs quiet.

Choosing numbers
A starting point
| Setting | Reasonable start | Why |
|---|---|---|
| Connect timeout | 3.05 s | just over one TCP retransmission window, per the Requests docs |
| Read timeout | 10 to 30 s | depends on how slow the API is on a good day |
| Total retries | 3 to 5 | enough to ride out a brief outage |
| Backoff factor | 0.5 to 1 | waits of 0, 1, 2, 4 s or 0, 2, 4, 8 s |
| Status codes | 429, 500, 502, 503, 504 | temporary failures; 4xx errors like 404 won’t fix themselves |
| Methods | default | add POST only with an idempotency key |
Worst-case time
Retries multiply timeouts. Five retries with a 10-second read timeout and a backoff factor of 1 can take up to six attempts of 10 seconds plus 0 + 2 + 4 + 8 + 16 seconds of sleep, 90 seconds in all, before the call finally fails. A scheduled job that runs every minute needs a smaller budget, or it will start overlapping with itself.
Sources
- Requests documentation, “Advanced Usage,” Timeouts: https://requests.readthedocs.io/en/latest/user/advanced/
- urllib3 documentation,
urllib3.utilreference (Retry): https://urllib3.readthedocs.io/en/stable/reference/urllib3.util.html
