Python requests default timeout: there isn't one

Python Requests has no default timeout: without timeout= a call can hang indefinitely. Set (connect, read) on every call, and keep it short for job APIs.

5 min readSume
All posts

Python Requests has no default timeout. If you don't pass timeout=, Requests does not time out, and the call can hang indefinitely while it waits for a server that never answers. Pass timeout=(connect, read) on every call, for example timeout=(3.05, 27).

The Requests facts come from its own Quickstart, Advanced Usage and Developer Interface pages. The slow-API example is Sume's video generation API, from Jobs and results and Video Generation. All were read on 2026-09-29.

What is the default timeout in Python requests?

None. In the Developer Interface, timeout is an optional parameter whose default is None, and the Advanced Usage page says "requests do not time out unless a timeout value is set explicitly. Without a timeout, your code may hang for minutes or more." The Quickstart says nearly all production code should use this parameter in nearly all requests.

The same applies to requests.post, requests.get and calls made through a Session: each call takes its own timeout argument.

How do I set a timeout in requests?

Pass one number or a tuple. The table shows what each form does.

From the Requests Advanced Usage and Developer Interface pages, read 2026-09-29.
You passWhat Requests does
NothingDoesn't time out
timeout=5Applies 5 seconds to both the connect and the read timeout
timeout=(3.05, 27)3.05 s to connect, 27 s to wait for the server to send data
timeout=NoneWaits forever for a response
Timed out while connectingRaises ConnectTimeout, which the docs call safe to retry
Timed out waiting for dataRaises ReadTimeout; catching Timeout catches both

What does the timeout actually measure?

Not the total time of the request. Four rules from the Requests docs:

  • The read timeout is not a limit on the whole download. Requests raises an exception when no bytes arrive on the socket for that many seconds.
  • Neither timeout is wall clock, so a request can run longer in real time than the number you set.
  • The connect timeout applies to each connection attempt to an IP address. A host with both IPv4 and IPv6 addresses can double the time you wait to connect.
  • Requests suggests a connect timeout slightly larger than a multiple of 3, the default TCP packet retransmission window.

What timeout should I use for a slow API?

Size the timeout to the HTTP response, not to the work. A video job can run for minutes, but Sume's create call, POST /v1/videos, answers at once with a job id and a polling_url; you poll that URL until the status is completed. Short timeouts on both calls are enough:

import os
import requests

auth = {"Authorization": f"Bearer {os.environ['SUME_API_KEY']}"}
body = {
    "model": "sume/auto",
    "prompt": "A vertical product clip on a desk, natural light",
    "aspect_ratio": "9:16",
    "duration": 5,
}
r = requests.post(
    "https://api.sume.com/v1/videos",
    json=body,
    headers={**auth, "Idempotency-Key": "order-8823-clip-v1"},
    timeout=(3.05, 30),
)
r.raise_for_status()
job = r.json()  # id, polling_url, status "pending"

s = requests.get(job["polling_url"], headers=auth, timeout=(3.05, 10))
print(s.json()["status"])

What happens to the job when requests times out?

A client-side timeout does not cancel the job: it keeps running and still bills, as Text-to-video API in Python also notes with the full submit, poll and download script.

If the create itself raised ReadTimeout, you can't tell whether the job was made. Resend it with the same Idempotency-Key and the same body: on /v1/videos, a replay returns the original job. Without a key, Sume's docs say not to retry an unsafe submit at all. Requests itself does not retry failed connections by default; Python requests retry shows a retry policy with backoff.

Sources

Related posts

More in Developers

All Developers posts

Written by Sume