A proxy timeout is the limit on how long a request waits at a given stage. The client splits the wait into stages: opening the connection, reading the response, sending the body, taking a connection from the pool and the request as a whole. With a proxy, the trap is the CONNECT step. The TCP connection to the proxy opens quickly. The real wait is the proxy reaching the target, and each library maps that wait to a different limit. This post covers the timeout types, the settings in five tools, our test results and how to pick values.
Five timeout types
Each timeout measures one stage of the request. A number set without knowing which stage it limits cuts in the wrong place.
- Connect: The time allowed to open a TCP connection to the server. With a proxy, that server is the proxy itself, not the target site.
- Read: The time allowed between two chunks of data from the server. It is not the total download time. Every new byte resets the counter.
- Write: The time allowed to send one chunk of the request body. It matters for large uploads.
- Pool: The time allowed to wait for a free connection when the connection pool is full. It kicks in when concurrent requests exceed the connection limit.
- Total: The cap on the time from the start of the request to the last byte of the body.
Not every tool offers all of these. The table below shows which setting does which job:
| Tool | Connect | Read | Total |
|---|---|---|---|
| requests | timeout=(c, r) first value | second value | none |
| httpx | connect= | read= | none |
| aiohttp | sock_connect=, connect= | sock_read= | total= |
| Node (undici) | connectTimeout | headersTimeout, bodyTimeout | AbortSignal.timeout() |
| curl | --connect-timeout | no separate option | --max-time |
requests has no default timeout. Its docs say so plainly: without a value, a request can hang for minutes or longer. A single number applies to both connect and read. httpx defaults to 5 seconds for every type. In aiohttp 3.13.3 the session defaults are total=300 and sock_connect=30 seconds.
The CONNECT wait
For an HTTPS target, the client first connects to the proxy, then sends a CONNECT request. The proxy connects to the target and only then returns 200 Connection established. The time between those two steps is how long the proxy takes to reach the target or its exit node. Connecting to the proxy is one round trip. Reaching the target adds a second leg on top.
Here is the trap: this wait is neither a pure connect nor a pure read. Each library ties it to a different limit. We set up our local test proxy to delay the CONNECT reply by 30 seconds, then gave 2 seconds for connect and 5 for read:
| Tool and setting | Result | Error |
|---|---|---|
requests timeout=(2, 5) | Cut at 2 s | ReadTimeout |
httpx connect=2, read=5 | Cut at 5 s | ReadTimeout |
aiohttp sock_connect=2, sock_read=5 | Not cut, waited for the proxy reply | — |
undici connectTimeout, headersTimeout | Not cut, waited for the proxy reply | — |
curl --connect-timeout 2 | Cut at 2 s | (28) |
The requests result needs a second look. The time came from the connect value, but the error was named ReadTimeout and the message said read timeout=2. httpx tied the same wait to the read limit. In aiohttp, connect or total cuts this wait: with connect=4 we got ConnectionTimeoutError at 4 seconds. In Node, only AbortSignal.timeout() cut it.
The takeaway is simple. Do not assume the connect limit covers reaching the target. Check the table for the limit your tool ties this wait to, and always set a total limit.
Python settings
In requests, pass both values as a tuple. The values below are examples, adjust them to your own measurements:
import requests
proxies = {
"http": "http://user:pass@pr.proxynet.io:8000",
"https": "http://user:pass@pr.proxynet.io:8000",
}
try:
r = requests.get("https://example.com", proxies=proxies, timeout=(5, 30))
except requests.exceptions.ProxyError as e:
print("Could not reach the proxy:", e)
except requests.exceptions.Timeout as e:
print("Timeout:", type(e).__name__)The ProxyError block is separate on purpose. In our test, when the proxy was unreachable, requests raised ProxyError, not ConnectTimeout. This class is not a subclass of Timeout. If you only write except requests.Timeout, this error slips through.
requests has no total limit. If a response sends one byte every 4 seconds, a 5-second read limit never fires. httpx has no total limit either. If you need one, use aiohttp or Node: both offer it directly.
In httpx, one Timeout object carries all four types:
import httpx
timeout = httpx.Timeout(10.0, connect=5.0)
with httpx.Client(proxy="http://user:pass@pr.proxynet.io:8000", timeout=timeout) as client:
try:
r = client.get("https://example.com")
except httpx.ConnectTimeout:
print("Could not connect to the proxy")
except httpx.ReadTimeout:
print("No response")
except httpx.PoolTimeout:
print("No free connection in the pool")The first value sets the read, write and pool limits together, and connect= sets the connect limit apart. The pool limit shows up in concurrent work. In our test we started two requests with max_connections=1 and pool=1. The second one got PoolTimeout after 1.02 seconds.
In aiohttp, set four fields together:
import asyncio
import aiohttp
PROXY = "http://user:pass@pr.proxynet.io:8000"
async def main():
timeout = aiohttp.ClientTimeout(total=60, connect=15, sock_connect=5, sock_read=30)
async with aiohttp.ClientSession(timeout=timeout) as session:
try:
async with session.get("https://example.com", proxy=PROXY) as r:
body = await r.text()
print(r.status, len(body))
except TimeoutError as e:
print("Timeout:", type(e).__name__)
asyncio.run(main())sock_connect measures only the TCP connection. connect also covers the pool wait and the proxy handshake. In our test, all three timeout errors we got from aiohttp derived from Python's TimeoutError class. One except block is enough.
Node.js and curl settings
In Node, proxying goes through the ProxyAgent class from the undici package. The agent carries the connect and read limits, while the total limit comes from the request signal:
import { fetch, ProxyAgent } from "undici";
const dispatcher = new ProxyAgent({
uri: "http://user:pass@pr.proxynet.io:8000",
connectTimeout: 5_000,
headersTimeout: 30_000,
bodyTimeout: 30_000,
});
try {
const res = await fetch("https://example.com", {
dispatcher,
signal: AbortSignal.timeout(60_000),
});
console.log(res.status, (await res.text()).length);
} catch (err) {
if (err.name === "TimeoutError") console.log("Total time exceeded");
else console.log(err.cause?.code ?? err.message);
}headersTimeout measures the first response headers, bodyTimeout the gap between body chunks. In our test, headersTimeout fired UND_ERR_HEADERS_TIMEOUT after 5 seconds on a tunneled request. HTTPS targets always go through a tunnel. On a plain http:// target, though, the headersTimeout given to ProxyAgent was not applied and the request waited 30 seconds. So do not skip the AbortSignal.timeout() line. Connection errors arrive in err.cause.code, with details in our post on TypeError: fetch failed in Node.js.
In curl, two flags are enough:
curl -x http://user:pass@pr.proxynet.io:8000 \
--connect-timeout 5 \
--max-time 60 \
https://example.comIn our test, --connect-timeout also covered the CONNECT wait. --max-time cuts the whole transfer. There is no separate read flag. To catch a stalled transfer, add --speed-limit 1 --speed-time 5: curl stops if less than 1 byte per second arrives for 5 seconds. Both cases exit with code 28.
Choosing values
The right value depends on your network, the proxy type and the target. Measure your own times instead of copying someone else's numbers. With a Residential Proxy, traffic exits from a device on a home connection. Latency can be higher and more variable than on a datacenter IP.
A few dozen requests to a light URL are enough to measure:
import statistics, time
import requests
proxies = {"https": "http://user:pass@pr.proxynet.io:8000"}
times = []
for _ in range(20):
t0 = time.perf_counter()
requests.get("https://example.com", proxies=proxies, timeout=(10, 60))
times.append(time.perf_counter() - t0)
time.sleep(1) # avoid loading the target
print("p95:", round(statistics.quantiles(times, n=20)[-1], 2))
print("slowest:", round(max(times), 2))Turn the results into three limits:
- Connect: Connecting to the proxy is fast, so this limit does not need to be long. The requests docs suggest a value slightly larger than a multiple of 3, because the TCP retransmission window is 3 seconds. If the host name resolves to several IPs, the limit applies to each address separately.
- Read: Add headroom above the slowest successful response you measured. In some libraries the CONNECT wait lands on this limit.
- Total: Set the longest legitimate duration of the job. A job that downloads a large file and a job that fetches one page do not get the same value.
Do not retry right after a timeout. Retry a limited number of times with growing intervals. The logic is the same as the code in our post on exponential backoff for 429 errors. With a Rotating Proxy setup, each new attempt opens a new connection and gets a different exit IP.
Debugging
The error name tells you which stage was cut. In our test, the same failure showed up under these names in the five tools:
| Error | Stage | Check first |
|---|---|---|
requests ProxyError, httpx ConnectTimeout, aiohttp ConnectionTimeoutError | Connection to the proxy | Host, port, firewall |
undici UND_ERR_CONNECT_TIMEOUT, curl (28) Connection timed out | Connection to the proxy | Host, port, firewall |
requests and httpx ReadTimeout, aiohttp SocketTimeoutError, undici UND_ERR_HEADERS_TIMEOUT | CONNECT or response | Target speed, read limit |
httpx PoolTimeout | Pool | Concurrency and connection limit |
aiohttp TimeoutError, AbortSignal TimeoutError, curl (28) Operation timed out | Total | Total limit and response size |
The ProxyError message in requests is a long chain. If it ends with Unable to connect to proxy and connect timeout=…, the problem is on the path to the proxy. We unpacked the "Max retries exceeded" phrase at the start of the chain in Max Retries Exceeded With URL.
If the error always arrives after the same time, a limit is cutting the request, not the network. If the time varies and the error is ReadTimeout, first try the target without the proxy.
How we tested
We ran the tests on December 1, 2026, on Windows 11. Versions: Python 3.13, requests 2.34.2 (urllib3 2.6.3), httpx 0.28.1, aiohttp 3.13.3, Node.js 24.22.2 with undici 8.10.0, and curl 8.22.0.
The setup was local and repeatable. We wrote two proxies with Python asyncio: one answered CONNECT at once, the other after 30 seconds. The target server offered three paths: a fast response, a path that delayed headers by 30 seconds and a path that sent 12 bytes at one byte per second. For an unreachable proxy we used the non-responding address 10.255.255.1. In every scenario, connect was 2 seconds and read was 5.
On the slow body, the read limit of requests, httpx and aiohttp never fired. All three finished the request successfully in 12 seconds. With an 8-second total limit, aiohttp cut at about 9 seconds, Node and curl at 8. The aiohttp gap comes from rounding: durations of 5 seconds and above are rounded up to the next whole second.
The bottom line
Set connect, read and total time separately. Derive the values from your own measurements and retry with growing intervals after a timeout. On networks with variable latency, such as residential, this split matters even more. Above all, never run requests without a timeout: its default is to wait forever.
Sources
- Requests docs, Advanced Usage, Timeouts: requests.readthedocs.io
- HTTPX docs, Timeouts: python-httpx.org
- aiohttp docs, Client Quickstart, Timeouts: docs.aiohttp.org
- AbortSignal.timeout(): developer.mozilla.org
- Everything curl, Timeouts: everything.curl.dev
Frequently asked questions
Does requests have a default timeout?
No. Without a value, requests applies no timeout and waits until a response arrives. If the proxy or the target stalls, the script can hang for minutes or indefinitely. Add timeout=(connect, read) to every call or define a default in your own Session wrapper. A single number applies to both stages.
What does the connect timeout measure with a proxy?
The TCP connection to the proxy. The connection to the target site is made on the proxy side, during the CONNECT step. In our test, requests tied this wait to the connect value and httpx to the read limit. In aiohttp the connect or total limit cut it, in curl --connect-timeout. In Node, only AbortSignal.timeout() cut it.
Does the read timeout limit the total download time?
No. The read limit measures the gap between two chunks of data and resets with every new byte. In our test, a response sending one byte per second finished successfully in 12 seconds despite a 5-second read limit. For the total time, use total in aiohttp, AbortSignal.timeout() in Node and --max-time in curl.
How many seconds should a proxy timeout be?
There is no single value that fits everyone. Send a few dozen requests to a light URL through your own proxy type and measure the times. Keep the connect limit short, set the read limit above the slowest successful response and the total limit by the longest legitimate duration of the job. Latency on residential connections can be more variable.
What does curl error 28 mean?
A timeout. If the message is Connection timed out, the connect stage exceeded --connect-timeout. In our test, a proxy delaying its CONNECT reply produced the same message. If the message is Operation timed out, --max-time ran out. Operation too slow means the speed limit you set with --speed-limit and --speed-time fired.
Should I retry a request after a timeout?
Yes, but a limited number of times and with growing intervals. An immediate retry can land on the same slow path and adds load to the target. Retrying is safe for requests like GET that can be repeated. For POST requests such as a payment or a sign-up, you cannot know whether the first request reached the server. Check the result before retrying those.




