[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"blog-post-python-requests-timeout-en":3},{"post":4,"faq":35,"faqLdJson":55,"faqLdJsonScript":80,"alternatePaths":81,"recommendations":84,"contentLocale":21},{"authors":5,"custom_excerpt":13,"excerpt":13,"feature_image":14,"featured":15,"id":16,"meta_description":17,"meta_title":18,"og_description":8,"og_image":8,"og_title":8,"primary_author":19,"primary_tag":20,"published_at":23,"reading_time":24,"slug":25,"status":26,"tags":27,"title":18,"twitter_description":8,"twitter_image":8,"twitter_title":32,"updated_at":33,"visibility":22,"lexical":34},[6],{"bio":7,"facebook":8,"instagram":8,"linkedin":8,"location":9,"name":10,"profile_image":11,"slug":12,"tiktok":8,"twitter":8,"website":8,"youtube":8},"At Rola IP, Adrian Cole writes about proxy infrastructure, including residential and datacenter proxies, IP routing, session persistence, and rotation, helping users balance reliability, performance, and cost.",null,"Adrian Cole在Rola IP负责代理网络基础设施相关内容，主要关注住宅代理与机房代理差异、IP路由、会话保持、IP轮换和连接稳定性，帮助用户理解性能、可用性与成本之间的权衡。","Adrian Cole","https:\u002F\u002Frola-ip.co\u002Fstatic\u002Fcontent\u002Fimages\u002F2026\u002F07\u002FPixPin_2026-07-21_14-45-20.png","adrian","Learn how to set Python Requests timeouts for GET and POST, use connect\u002Fread tuples, handle timeout errors, set Session defaults, and debug proxy failures.","https:\u002F\u002Frola-ip.co\u002Fstatic\u002Fcontent\u002Fimages\u002F2026\u002F07\u002FPython-requests-timeout-1.webp",false,"6a5f27314956c90001bebc3e","Learn how to set Python Requests timeouts for GET and POST, use connect\u002Fread tuples, handle timeout errors, set Session defaults, and debug proxy failures.\n","Python Requests Timeout Guide: GET, POST, and Session Defaults",{"bio":7,"facebook":8,"instagram":8,"linkedin":8,"location":9,"name":10,"profile_image":11,"slug":12,"tiktok":8,"twitter":8,"website":8,"youtube":8},{"description":8,"feature_image":8,"name":21,"slug":21,"visibility":22},"en","public","2026-07-21T09:53:57.000Z",10,"python-requests-timeout","published",[28,29],{"description":8,"feature_image":8,"name":21,"slug":21,"visibility":22},{"description":8,"feature_image":8,"name":30,"slug":31,"visibility":22},"教程","guides","Python Requests Timeout","2026-09-08T02:45:05.000Z","{\"root\":{\"children\":[{\"type\":\"markdown\",\"version\":1,\"markdown\":\"Python Requests does not set a timeout automatically. This guide shows safe GET and POST examples, explains connect and read timeout behavior, handles timeout exceptions, sets a real Session default, adds restrained retries, and diagnoses direct-versus-proxy failures.\\n\\nA **Python Requests timeout** is not enabled automatically. If you call `requests.get()` or `requests.post()` without a `timeout` argument, Requests can keep waiting while the network stack, remote server, or an intermediary remains unresponsive. The practical fix is to pass an explicit timeout to every external request and handle the resulting exception deliberately.\\n\\nThe important detail is what that value means. A Requests timeout is not a stopwatch for the complete request and response download. It controls how long Requests waits during connection establishment and how long it tolerates a pause while reading response data. You can use one value for both phases or a tuple that gives each phase a separate limit.\\n\\nWhere this guide mentions local testing, it refers to the environment listed below. The guide covers normal GET and POST calls, separate connect and read values, exception handling, Session defaults, bounded retries, and proxy-specific diagnosis.\\n\\n## TL;DR\\n\\n> - Requests does not apply a timeout unless you pass one explicitly.\\n> - Use `timeout=(connect, read)` when connection setup and response delivery need different limits.\\n> - Catch timeout exceptions separately when the recovery path depends on whether the failure happened during connect or read.\\n> - Do not treat `timeout=5` as a hard wall-clock deadline for the full request lifecycle.\\n\\n## Quick start: a safe default pattern\\n\\nIf you need one copy-paste example first, use this pattern:\\n\\n```python\\nimport requests\\n\\ntry:\\n    response = requests.get(\\n        \\\"https:\u002F\u002Fpostman-echo.com\u002Fget\\\",\\n        timeout=(3.05, 20),\\n    )\\n    response.raise_for_status()\\n    print(response.json()[\\\"url\\\"])\\nexcept requests.exceptions.ConnectTimeout:\\n    print(\\\"The connection took too long to establish.\\\")\\nexcept requests.exceptions.ReadTimeout:\\n    print(\\\"The server stopped sending data before the read timeout.\\\")\\nexcept requests.exceptions.RequestException as error:\\n    print(f\\\"Another Requests error occurred: {error}\\\")\\n```\\n\\nUse a tuple when you want a shorter connect limit and a longer read limit. If you need a hard total deadline, enforce it outside Requests with a worker timeout, task budget, or other higher-level control.\\n\\n## Tested environment and prerequisites\\n\\n| Component | Tested value | Purpose |\\n|---|---|---|\\n| Operating system | Windows 11, build 26200 | Test host |\\n| Python | 3.12.13 | Runtime |\\n| Requests | 2.34.2 | HTTP client |\\n| urllib3 | 2.7.0 | Transport and retry support used by Requests |\\n| Public test service | Postman Echo | Safe GET and POST request reflection |\\n\\nRequests 2.34.2 requires Python 3.10 or newer. Install the tested release in a virtual environment so the tutorial does not change packages used by another project:\\n\\n```powershell\\npython -m venv .venv\\n.\\\\.venv\\\\Scripts\\\\Activate.ps1\\npython -m pip install \\\"requests==2.34.2\\\"\\npython -c \\\"import requests; print(requests.__version__)\\\"\\n```\\n\\nOn macOS or Linux, activate the environment with `source .venv\u002Fbin\u002Factivate`. The final command should print `2.34.2` for this exact test setup. A later Requests release may also work, but verify its documentation and rerun the examples before publishing derived instructions.\\n\\nLocal verification notes for this article:\\n\\n- Public success examples use Postman Echo for simple GET and POST reflection.\\n- Timeout exception behavior was reproduced in local testing with a local HTTP server that paused before sending response bytes.\\n- `session.timeout = ...` was checked in the test environment described above to confirm that the attribute exists on the object but is not consumed by `Session.request()`.\\n- Retry behavior was checked in local testing with a local endpoint that returned `503` once and `200` on the next attempt.\\n\\n## What is the Python Requests default timeout?\\n\\nThe **Python Requests default timeout** is effectively no timeout. More precisely, the default argument is `None`, so Requests does not impose a connect or read limit unless your code supplies one. The official Quickstart warns that omitting the value can leave a program waiting indefinitely.\\n\\nThis call has no Requests-level timeout:\\n\\n```python\\nimport requests\\n\\nresponse = requests.get(\\\"https:\u002F\u002Fpostman-echo.com\u002Fget\\\")\\n```\\n\\nAdding a scalar applies the same numeric value to the connect and read phases:\\n\\n```python\\nimport requests\\n\\nresponse = requests.get(\\\"https:\u002F\u002Fpostman-echo.com\u002Fget\\\", timeout=10)\\n```\\n\\nThat does not promise completion within ten wall-clock seconds. A connection can involve more than one IP-address attempt, and the read limit concerns periods without incoming bytes rather than the total duration of a large response body. Treat the value as an inactivity boundary, not as an end-to-end service-level deadline.\\n\\n## Set a Python Requests GET timeout\\n\\nA **Python Requests GET timeout** is passed directly to `requests.get()`. Use `raise_for_status()` separately because a timeout and an HTTP error answer different questions: a timeout means a network phase waited too long, while `404`, `429`, or `500` is a completed HTTP response with an error status.\\n\\n```python\\nimport requests\\n\\nresponse = requests.get(\\n    \\\"https:\u002F\u002Fpostman-echo.com\u002Fget\\\",\\n    timeout=20,\\n)\\nresponse.raise_for_status()\\n\\nprint(response.status_code)\\nprint(response.json()[\\\"url\\\"])\\n```\\n\\nThe tested output was:\\n\\n```text\\n200\\nhttps:\u002F\u002Fpostman-echo.com\u002Fget\\n```\\n\\nDo not copy `20` into every project without thought. Start from the expected latency of the service, measure normal and high-percentile response times, and leave enough margin for routine network variation. A user-facing API call and a scheduled export may need very different read limits.\\n\\n## Set a Python Requests POST timeout\\n\\nA **Python Requests POST timeout** uses the same parameter. The method does not require a special timeout API; `requests.post()` forwards supported request options through the normal Requests pipeline.\\n\\n```python\\nimport requests\\n\\nresponse = requests.post(\\n    \\\"https:\u002F\u002Fpostman-echo.com\u002Fpost\\\",\\n    json={\\\"task\\\": \\\"timeout-test\\\"},\\n    timeout=(3.05, 20),\\n)\\nresponse.raise_for_status()\\n\\nprint(response.status_code)\\nprint(response.json()[\\\"json\\\"])\\n```\\n\\nThe tested output was:\\n\\n```text\\n200\\n{'task': 'timeout-test'}\\n```\\n\\nThe timeout mechanics are the same for GET and POST, but retry decisions are not. GET is normally intended to be idempotent. A POST may create an order, charge a card, or submit a job before the client loses the response. Retrying that POST automatically can duplicate the side effect unless the API supports an idempotency key or documents another safe retry mechanism.\\n\\n## Split connect and read timeouts\\n\\nUse a two-item tuple when connection establishment and response generation have different budgets:\\n\\n```python\\nresponse = requests.get(\\n    \\\"https:\u002F\u002Fpostman-echo.com\u002Fget\\\",\\n    timeout=(3.05, 20),\\n)\\n```\\n\\nThe first number is the connect timeout. It limits each attempt to establish a socket connection to a resolved IP address. If a hostname resolves to multiple addresses, the underlying transport may try them sequentially, so the elapsed connection time can exceed one connect value.\\n\\nThe second number is the read timeout. It limits how long Requests waits between bytes after the connection is established and the request has been sent. It commonly acts as the wait for the first response byte, but it is not a cap on the total download. A server that keeps sending small chunks before the interval expires can take longer than the configured read value to finish the body.\\n\\n| Form | Meaning | Appropriate use |\\n|---|---|---|\\n| `timeout=10` | Apply 10 seconds to both connect and read inactivity | Simple calls with similar phase budgets |\\n| `timeout=(3.05, 20)` | Allow 3.05 seconds per connect attempt and 20 seconds between received bytes | APIs with quick connections but slower processing |\\n| `timeout=None` | Apply no Requests timeout | Rare, deliberate cases only; unsafe as a casual default |\\n\\nIf the application needs a hard total deadline, Requests' normal tuple does not provide that guarantee. Enforce the deadline at a higher level, such as a worker timeout, process boundary, task queue, or client architecture designed around a total budget. Test cancellation behavior carefully because stopping a waiting thread is not the same as canceling an asynchronous operation.\\n\\n## Catch timeout exceptions without hiding other failures\\n\\nRequests exposes separate connection and read exceptions plus their shared parent. Catch the specific types when the recovery action or log message differs:\\n\\n```python\\nimport requests\\n\\ntry:\\n    response = requests.get(\\n        \\\"https:\u002F\u002Fpostman-echo.com\u002Fget\\\",\\n        timeout=(3.05, 20),\\n    )\\n    response.raise_for_status()\\nexcept requests.exceptions.ConnectTimeout:\\n    print(\\\"Connection setup exceeded the connect timeout\\\")\\nexcept requests.exceptions.ReadTimeout:\\n    print(\\\"The server stopped sending data within the read timeout\\\")\\nexcept requests.exceptions.RequestException as error:\\n    print(f\\\"The request failed for another reason: {error}\\\")\\nelse:\\n    print(response.status_code)\\n```\\n\\nIf both timeout phases have the same recovery path, catch `requests.exceptions.Timeout` instead. It is the parent of `ConnectTimeout` and `ReadTimeout`. Keep a broader `RequestException` handler after the timeout handler so DNS failures, refused connections, redirect problems, TLS errors, and HTTP errors are not mislabeled as timeouts.\\n\\nIn local testing with the environment described above, the exception branches were checked against a local HTTP server that paused for 0.25 seconds while the client used a 0.05-second read timeout. That run raised `ReadTimeout`. Depending on a public `\u002Fdelay` endpoint for this check is fragile, which is why the successful public examples use Postman Echo instead.\\n\\n## Set a real default timeout for a Session\\n\\nOne common tutorial error is assigning a new attribute:\\n\\n```python\\nsession = requests.Session()\\nsession.timeout = 10  # This does not configure Session.request().\\n```\\n\\nPython allows that attribute to exist, but Requests does not read it when building the request. In local testing with the environment described above, `session.timeout = 0.05` was followed by a local response that took more than 0.20 seconds, and the request still completed.\\n\\nCreate a small Session subclass and supply the default through the actual request keyword arguments:\\n\\n```python\\nimport requests\\n\\n\\nclass TimeoutSession(requests.Session):\\n    def __init__(self, timeout=(3.05, 20)):\\n        super().__init__()\\n        self.default_timeout = timeout\\n\\n    def request(self, method, url, **kwargs):\\n        kwargs.setdefault(\\\"timeout\\\", self.default_timeout)\\n        return super().request(method, url, **kwargs)\\n\\n\\nwith TimeoutSession() as session:\\n    response = session.get(\\\"https:\u002F\u002Fpostman-echo.com\u002Fget\\\")\\n    response.raise_for_status()\\n    print(response.status_code)\\n```\\n\\n`setdefault()` preserves an explicit per-call override:\\n\\n```python\\nwith TimeoutSession() as session:\\n    response = session.get(\\\"https:\u002F\u002Fpostman-echo.com\u002Fget\\\", timeout=(5, 60))\\n    response.raise_for_status()\\n```\\n\\nA caller can also pass `timeout=None`, which intentionally disables the default because the key is present. Decide whether your wrapper should permit that behavior. For a strict internal client, you may reject `None` instead of silently accepting it.\\n\\n## Add retries only where the operation is safe\\n\\nRequests does not retry failed connections by default. You can mount an `HTTPAdapter` with urllib3's `Retry` policy, but keep attempts bounded and restrict the allowed methods:\\n\\n```python\\nimport requests\\nfrom requests.adapters import HTTPAdapter\\nfrom urllib3.util import Retry\\n\\nretry_policy = Retry(\\n    total=2,\\n    status_forcelist=[429, 502, 503, 504],\\n    allowed_methods={\\\"GET\\\", \\\"HEAD\\\"},\\n    backoff_factor=0.5,\\n    respect_retry_after_header=True,\\n)\\n\\nwith requests.Session() as session:\\n    session.mount(\\\"https:\u002F\u002F\\\", HTTPAdapter(max_retries=retry_policy))\\n    response = session.get(\\n        \\\"https:\u002F\u002Fpostman-echo.com\u002Fget\\\",\\n        timeout=(3.05, 20),\\n    )\\n    response.raise_for_status()\\n```\\n\\nIn local testing with the environment described above, the retry mechanism was checked with a server that returned `503` once and `200` on the next request. The final status was `200`, and the server recorded exactly two attempts.\\n\\nRetries are not a substitute for choosing a sensible timeout. Each new attempt consumes time and server capacity. Respect `Retry-After`, avoid unbounded loops, add jitter in large distributed workloads, and do not add POST to `allowed_methods` unless the operation is demonstrably idempotent.\\n\\n## Choose timeout values from evidence\\n\\nThere is no universal best Python HTTP request timeout. The same is true for any broader **Python request timeout** policy: a useful value comes from the operation's latency distribution, user-facing deadline, body size, network path, and failure cost.\\n\\nUse this process:\\n\\n1. Measure connection and response timing under normal load.\\n2. Separate fast connection setup from slow server processing with a tuple.\\n3. Test high-latency regions and any proxy route the production job will use.\\n4. Decide how many attempts fit inside the operation's total time budget.\\n5. Log the timeout phase, URL host, attempt number, elapsed time, and correlation ID without logging credentials or sensitive response data.\\n6. Review the values when the endpoint, region, payload, proxy, or service-level objective changes.\\n\\nShort values fail fast but can reject healthy requests during routine variance. Long values reduce false timeouts but tie up workers and delay failure handling. The right tradeoff is an operational decision, not a magic number copied from a tutorial.\\n\\n## Troubleshoot Python HTTP request timeout failures\\n\\n| Symptom | Likely cause | How to verify | Practical action |\\n|---|---|---|---|\\n| The script appears to hang | No timeout was supplied | Log timestamps immediately before and after the call | Add an explicit scalar or tuple and catch the timeout |\\n| `ConnectTimeout` occurs | Route, firewall, endpoint, or connection path is slow or unavailable | Test DNS resolution, TCP reachability, another network, and repeated attempts | Fix reachability; adjust connect value only after measurement |\\n| `ReadTimeout` occurs after connecting | Server processing or response delivery paused | Compare server logs, time to first byte, payload size, and a direct request | Increase read budget when justified or reduce server work\u002Fbody size |\\n| Elapsed time exceeds the tuple values | Multiple IP attempts or continuing response bytes | Record resolved addresses and stream timing | Do not treat the tuple as a wall-clock deadline |\\n| Only proxied calls time out | Proxy route, region, authentication, or endpoint health differs | Send the same authorized request directly and through the proxy; compare phase and latency | Fix credentials or route, choose a healthier endpoint, then tune values |\\n| Timeout appears with `403` or `429` | The timeout and access\u002Frate-limit response may be separate problems | Log status codes and relevant response headers before retrying | Reduce request rate, respect policy, and follow documented access rules |\\n| Retries make the job slower | Attempts are too numerous or backoff exceeds the budget | Log attempt count and cumulative elapsed time | Lower retry count, cap backoff, and fail clearly |\\n\\nAvoid disabling TLS verification to make a timeout disappear. `verify=False` changes certificate validation and exposes the connection to man-in-the-middle risk; it does not solve connect\u002Fread budgeting.\\n\\n## Diagnose timeouts in proxy and scraping workflows\\n\\nIn legitimate public web data collection, a timeout may occur at the target server, local network, proxy connection, or response path. Change one variable at a time. First run the same authorized request directly. Then run it through the proxy with the same URL, headers, payload, and timeout tuple. Record whether the failure is connect or read related, plus elapsed time and HTTP status when a response exists.\\n\\nIf the direct call succeeds consistently but the proxied call fails, inspect proxy authentication, endpoint location, route latency, session settings, and IP health before simply increasing the timeout. The [Rola IP website](https:\u002F\u002Frola-ip.co\u002F) provides product context, and the [Rola IP documentation center](https:\u002F\u002Fdoc.rola-ip.co\u002Fen\u002F) is the better next step when you need Python proxy configuration details.\\n\\nProxy infrastructure does not replace timeout handling, bounded retries, rate limits, or application-level error reporting. It also does not grant permission to collect data. Follow the target site's terms, applicable robots policies, contractual restrictions, rate limits, and relevant laws.\\n\\n## Limits that `timeout` does not enforce\\n\\nRequests' `timeout` argument does not automatically provide all of these controls:\\n\\n- a guaranteed deadline for DNS resolution, connection attempts, redirects, and the full body combined;\\n- a maximum response-body size;\\n- a maximum number of redirects unless separately configured;\\n- automatic cancellation of unrelated application work;\\n- safe retries for non-idempotent operations;\\n- protection from a server that sends bytes slowly enough to keep resetting the read interval.\\n\\nFor large downloads, use streaming, validate `Content-Length` when available, count received bytes, and stop when your own size or elapsed-time policy is exceeded. For strict deadlines or high concurrency, evaluate a client and architecture with explicit total-time and cancellation semantics rather than forcing Requests to behave like an asynchronous runtime.\\n\\n\\n## Conclusion\\n\\nReliable Requests code sets a timeout explicitly, treats connect and read phases separately when useful, and never confuses inactivity limits with a complete wall-clock deadline. Add specific exception handling, enforce Session defaults through the request arguments, and keep retries bounded to safe methods.\\n\\nWhen a timeout appears only through a proxy, compare an equivalent direct request before changing values. That simple control test separates application behavior from route-specific latency and leads to a fix based on evidence rather than guesswork.\"},{\"children\":[],\"direction\":null,\"format\":\"\",\"indent\":0,\"type\":\"paragraph\",\"version\":1}],\"direction\":null,\"format\":\"\",\"indent\":0,\"type\":\"root\",\"version\":1}}",{"items":36,"inline":15},[37,40,43,46,49,52],{"title":38,"desc":39},"What happens if I do not set a timeout in Python Requests?","\u003Cp dir=\"ltr\">\u003Cspan style=\"white-space: pre-wrap;\">Requests applies no timeout of its own. In practical terms, the call can keep waiting while the operating system, the network path, the remote service, or another layer stays unresponsive. That behavior is dangerous in production because it can block workers, delay retries, and make incident diagnosis harder. A safer default is to pass either a scalar timeout or a \u003C\u002Fspan>\u003Ccode spellcheck=\"false\" style=\"white-space: pre-wrap;\">\u003Cspan>(connect, read)\u003C\u002Fspan>\u003C\u002Fcode>\u003Cspan style=\"white-space: pre-wrap;\"> tuple on every external request, then log which phase failed so you can tune values with evidence instead of guesswork.\u003C\u002Fspan>\u003C\u002Fp>",{"title":41,"desc":42},"Does timeout=5 stop the entire request after five seconds?","\u003Cp dir=\"ltr\">\u003Cspan style=\"white-space: pre-wrap;\">No. The scalar value is applied to both connect and read timeout behavior, but it is not a hard wall-clock deadline for the entire request lifecycle. A hostname may resolve to multiple addresses, connection attempts can happen sequentially, and the read timeout is about inactivity between received bytes rather than total download time. If you need a strict end-to-end deadline, enforce it outside Requests with a worker timeout, a task budget, or an architecture that supports true cancellation and total-time control.\u003C\u002Fspan>\u003C\u002Fp>",{"title":44,"desc":45},"Should GET and POST use different timeout syntax?","\u003Cp dir=\"ltr\">\u003Cspan style=\"white-space: pre-wrap;\">No. GET and POST both accept either a scalar timeout or a \u003C\u002Fspan>\u003Ccode spellcheck=\"false\" style=\"white-space: pre-wrap;\">\u003Cspan>(connect, read)\u003C\u002Fspan>\u003C\u002Fcode>\u003Cspan style=\"white-space: pre-wrap;\"> tuple, so the syntax is the same. The more important distinction is what happens after a failure. GET requests are often safe to retry because they are intended to be idempotent, while a POST may already have created a side effect before the client times out waiting for the response. Choose timeout values the same way for both verbs, but choose retry behavior much more carefully for POST.\u003C\u002Fspan>\u003C\u002Fp>",{"title":47,"desc":48},"Can I set session.timeout = 10?","\u003Cp dir=\"ltr\">\u003Cspan style=\"white-space: pre-wrap;\">No. In Requests 2.34.2, assigning \u003C\u002Fspan>\u003Ccode spellcheck=\"false\" style=\"white-space: pre-wrap;\">\u003Cspan>session.timeout = 10\u003C\u002Fspan>\u003C\u002Fcode>\u003Cspan style=\"white-space: pre-wrap;\"> creates an attribute on the Python object, but \u003C\u002Fspan>\u003Ccode spellcheck=\"false\" style=\"white-space: pre-wrap;\">\u003Cspan>Session.request()\u003C\u002Fspan>\u003C\u002Fcode>\u003Cspan style=\"white-space: pre-wrap;\"> does not consume that attribute when building requests. That means the code looks reasonable while silently failing to enforce a default timeout. A safer pattern is to subclass \u003C\u002Fspan>\u003Ccode spellcheck=\"false\" style=\"white-space: pre-wrap;\">\u003Cspan>requests.Session\u003C\u002Fspan>\u003C\u002Fcode>\u003Cspan style=\"white-space: pre-wrap;\">, store your preferred default on the instance, and inject it through \u003C\u002Fspan>\u003Ccode spellcheck=\"false\" style=\"white-space: pre-wrap;\">\u003Cspan>kwargs.setdefault(\"timeout\", ...)\u003C\u002Fspan>\u003C\u002Fcode>\u003Cspan style=\"white-space: pre-wrap;\"> inside \u003C\u002Fspan>\u003Ccode spellcheck=\"false\" style=\"white-space: pre-wrap;\">\u003Cspan>request()\u003C\u002Fspan>\u003C\u002Fcode>\u003Cspan style=\"white-space: pre-wrap;\">. That approach preserves per-call overrides while still giving the session a real default.\u003C\u002Fspan>\u003C\u002Fp>",{"title":50,"desc":51},"Which exception should I catch?","\u003Cp dir=\"ltr\">\u003Cspan style=\"white-space: pre-wrap;\">Catch the most specific timeout exception your recovery logic actually needs. Use \u003C\u002Fspan>\u003Ccode spellcheck=\"false\" style=\"white-space: pre-wrap;\">\u003Cspan>ConnectTimeout\u003C\u002Fspan>\u003C\u002Fcode>\u003Cspan style=\"white-space: pre-wrap;\"> when connection setup failures should be handled differently from slow response delivery, and use \u003C\u002Fspan>\u003Ccode spellcheck=\"false\" style=\"white-space: pre-wrap;\">\u003Cspan>ReadTimeout\u003C\u002Fspan>\u003C\u002Fcode>\u003Cspan style=\"white-space: pre-wrap;\"> when the server connected successfully but stopped sending data in time. If both cases lead to the same retry or logging path, catch their parent \u003C\u002Fspan>\u003Ccode spellcheck=\"false\" style=\"white-space: pre-wrap;\">\u003Cspan>Timeout\u003C\u002Fspan>\u003C\u002Fcode>\u003Cspan style=\"white-space: pre-wrap;\"> instead. After that, keep a broader \u003C\u002Fspan>\u003Ccode spellcheck=\"false\" style=\"white-space: pre-wrap;\">\u003Cspan>RequestException\u003C\u002Fspan>\u003C\u002Fcode>\u003Cspan style=\"white-space: pre-wrap;\"> handler for non-timeout failures such as DNS errors, TLS issues, redirect problems, or HTTP errors raised by \u003C\u002Fspan>\u003Ccode spellcheck=\"false\" style=\"white-space: pre-wrap;\">\u003Cspan>raise_for_status()\u003C\u002Fspan>\u003C\u002Fcode>\u003Cspan style=\"white-space: pre-wrap;\">.\u003C\u002Fspan>\u003C\u002Fp>",{"title":53,"desc":54},"Should every timeout be retried?","\u003Cp dir=\"ltr\">\u003Cspan style=\"white-space: pre-wrap;\">No. A timeout should be retried only when the failure is plausibly temporary and the operation is safe to repeat. Retrying an idempotent GET after a transient \u003C\u002Fspan>\u003Ccode spellcheck=\"false\" style=\"white-space: pre-wrap;\">\u003Cspan>503\u003C\u002Fspan>\u003C\u002Fcode>\u003Cspan style=\"white-space: pre-wrap;\"> or a short-lived network issue can be reasonable, but automatically retrying a POST can duplicate orders, charges, or queued jobs unless the upstream API provides an idempotency guarantee. Keep retry counts small, respect \u003C\u002Fspan>\u003Ccode spellcheck=\"false\" style=\"white-space: pre-wrap;\">\u003Cspan>Retry-After\u003C\u002Fspan>\u003C\u002Fcode>\u003Cspan style=\"white-space: pre-wrap;\"> when it is present, and make sure the total time spent across all attempts still fits the larger operation budget.\u003C\u002Fspan>\u003C\u002Fp>",{"@context":56,"@type":57,"@id":58,"mainEntity":59},"https:\u002F\u002Fschema.org","FAQPage","https:\u002F\u002Frola-ip.co\u002Fblog\u002Fpython-requests-timeout\u002F#faq",[60,65,68,71,74,77],{"@type":61,"name":38,"acceptedAnswer":62},"Question",{"@type":63,"text":64},"Answer","Requests applies no timeout of its own. In practical terms, the call can keep waiting while the operating system, the network path, the remote service, or another layer stays unresponsive. That behavior is dangerous in production because it can block workers, delay retries, and make incident diagnosis harder. A safer default is to pass either a scalar timeout or a (connect, read) tuple on every external request, then log which phase failed so you can tune values with evidence instead of guesswork.",{"@type":61,"name":41,"acceptedAnswer":66},{"@type":63,"text":67},"No. The scalar value is applied to both connect and read timeout behavior, but it is not a hard wall-clock deadline for the entire request lifecycle. A hostname may resolve to multiple addresses, connection attempts can happen sequentially, and the read timeout is about inactivity between received bytes rather than total download time. If you need a strict end-to-end deadline, enforce it outside Requests with a worker timeout, a task budget, or an architecture that supports true cancellation and total-time control.",{"@type":61,"name":44,"acceptedAnswer":69},{"@type":63,"text":70},"No. GET and POST both accept either a scalar timeout or a (connect, read) tuple, so the syntax is the same. The more important distinction is what happens after a failure. GET requests are often safe to retry because they are intended to be idempotent, while a POST may already have created a side effect before the client times out waiting for the response. Choose timeout values the same way for both verbs, but choose retry behavior much more carefully for POST.",{"@type":61,"name":47,"acceptedAnswer":72},{"@type":63,"text":73},"No. In Requests 2.34.2, assigning session.timeout = 10 creates an attribute on the Python object, but Session.request() does not consume that attribute when building requests. That means the code looks reasonable while silently failing to enforce a default timeout. A safer pattern is to subclass requests.Session, store your preferred default on the instance, and inject it through kwargs.setdefault(\"timeout\", ...) inside request(). That approach preserves per-call overrides while still giving the session a real default.",{"@type":61,"name":50,"acceptedAnswer":75},{"@type":63,"text":76},"Catch the most specific timeout exception your recovery logic actually needs. Use ConnectTimeout when connection setup failures should be handled differently from slow response delivery, and use ReadTimeout when the server connected successfully but stopped sending data in time. If both cases lead to the same retry or logging path, catch their parent Timeout instead. After that, keep a broader RequestException handler for non-timeout failures such as DNS errors, TLS issues, redirect problems, or HTTP errors raised by raise_for_status().",{"@type":61,"name":53,"acceptedAnswer":78},{"@type":63,"text":79},"No. A timeout should be retried only when the failure is plausibly temporary and the operation is safe to repeat. Retrying an idempotent GET after a transient 503 or a short-lived network issue can be reasonable, but automatically retrying a POST can duplicate orders, charges, or queued jobs unless the upstream API provides an idempotency guarantee. Keep retry counts small, respect Retry-After when it is present, and make sure the total time spent across all attempts still fits the larger operation budget.","{\"@context\":\"https:\u002F\u002Fschema.org\",\"@type\":\"FAQPage\",\"@id\":\"https:\u002F\u002Frola-ip.co\u002Fblog\u002Fpython-requests-timeout\u002F#faq\",\"mainEntity\":[{\"@type\":\"Question\",\"name\":\"What happens if I do not set a timeout in Python Requests?\",\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"Requests applies no timeout of its own. In practical terms, the call can keep waiting while the operating system, the network path, the remote service, or another layer stays unresponsive. That behavior is dangerous in production because it can block workers, delay retries, and make incident diagnosis harder. A safer default is to pass either a scalar timeout or a (connect, read) tuple on every external request, then log which phase failed so you can tune values with evidence instead of guesswork.\"}},{\"@type\":\"Question\",\"name\":\"Does timeout=5 stop the entire request after five seconds?\",\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"No. The scalar value is applied to both connect and read timeout behavior, but it is not a hard wall-clock deadline for the entire request lifecycle. A hostname may resolve to multiple addresses, connection attempts can happen sequentially, and the read timeout is about inactivity between received bytes rather than total download time. If you need a strict end-to-end deadline, enforce it outside Requests with a worker timeout, a task budget, or an architecture that supports true cancellation and total-time control.\"}},{\"@type\":\"Question\",\"name\":\"Should GET and POST use different timeout syntax?\",\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"No. GET and POST both accept either a scalar timeout or a (connect, read) tuple, so the syntax is the same. The more important distinction is what happens after a failure. GET requests are often safe to retry because they are intended to be idempotent, while a POST may already have created a side effect before the client times out waiting for the response. Choose timeout values the same way for both verbs, but choose retry behavior much more carefully for POST.\"}},{\"@type\":\"Question\",\"name\":\"Can I set session.timeout = 10?\",\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"No. In Requests 2.34.2, assigning session.timeout = 10 creates an attribute on the Python object, but Session.request() does not consume that attribute when building requests. That means the code looks reasonable while silently failing to enforce a default timeout. A safer pattern is to subclass requests.Session, store your preferred default on the instance, and inject it through kwargs.setdefault(\\\"timeout\\\", ...) inside request(). That approach preserves per-call overrides while still giving the session a real default.\"}},{\"@type\":\"Question\",\"name\":\"Which exception should I catch?\",\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"Catch the most specific timeout exception your recovery logic actually needs. Use ConnectTimeout when connection setup failures should be handled differently from slow response delivery, and use ReadTimeout when the server connected successfully but stopped sending data in time. If both cases lead to the same retry or logging path, catch their parent Timeout instead. After that, keep a broader RequestException handler for non-timeout failures such as DNS errors, TLS issues, redirect problems, or HTTP errors raised by raise_for_status().\"}},{\"@type\":\"Question\",\"name\":\"Should every timeout be retried?\",\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"No. A timeout should be retried only when the failure is plausibly temporary and the operation is safe to repeat. Retrying an idempotent GET after a transient 503 or a short-lived network issue can be reasonable, but automatically retrying a POST can duplicate orders, charges, or queued jobs unless the upstream API provides an idempotency guarantee. Keep retry counts small, respect Retry-After when it is present, and make sure the total time spent across all attempts still fits the larger operation budget.\"}}]}",[82,83],"\u002Fblog\u002Fpython-requests-timeout\u002F","\u002Fzh\u002Fblog\u002Fpython-requests-timeout\u002F",{"prev":85,"next":8,"related":96,"popular":130,"latest":196},{"id":86,"title":87,"slug":88,"feature_image":89,"published_at":90,"twitter_title":91,"primary_tag":92,"tags":93},"6a5f5b6c4956c90001bebc92","Python Requests Headers Tutorial: GET, POST, and User-Agent","python-requests-headers","https:\u002F\u002Frola-ip.co\u002Fstatic\u002Fcontent\u002Fimages\u002F2026\u002F07\u002Fpython-requests-headers-1.webp","2026-07-21T12:09:40.000Z","Python Requests Headers",{"name":21,"slug":21},[94,95],{"name":21,"slug":21,"visibility":22},{"name":30,"slug":31,"visibility":22},[97,108,119],{"id":98,"title":99,"slug":100,"feature_image":101,"published_at":102,"twitter_title":103,"primary_tag":104,"tags":105},"6b0fc0b392ab700001dc0d27","How to Make Residential Proxies: DIY Setup Guide and Limits","how-to-make-residential-proxies","https:\u002F\u002Frola-ip.co\u002Fstatic\u002Fcontent\u002Fimages\u002F2026\u002F12\u002FHow-to-Make-Residential-Proxies_-DIY-Setup-Guide-and-Limits.webp","2026-12-02T07:02:29.000Z","how to make residential proxies",{"name":21,"slug":21},[106,107],{"name":21,"slug":21,"visibility":22},{"name":30,"slug":31,"visibility":22},{"id":109,"title":110,"slug":111,"feature_image":112,"published_at":113,"twitter_title":114,"primary_tag":115,"tags":116},"6b0e973a92ab700001dc0c73","Agent-Sim Proxy Setup on Linux: Routing and Exit-IP Checks","agent-sim-proxy-setup","https:\u002F\u002Frola-ip.co\u002Fstatic\u002Fcontent\u002Fimages\u002F2026\u002F12\u002FAgent-Sim-Proxy-Setup-1.webp","2026-12-01T09:54:13.000Z","Agent-Sim Proxy Setup",{"name":21,"slug":21},[117,118],{"name":21,"slug":21,"visibility":22},{"name":30,"slug":31,"visibility":22},{"id":120,"title":121,"slug":122,"feature_image":123,"published_at":124,"twitter_title":125,"primary_tag":126,"tags":127},"6b0d3e4b92ab700001dc0a73","Scrape Indeed Jobs with Python: Extract Job Fields and Export to CSV","scrape-indeed-jobs","https:\u002F\u002Frola-ip.co\u002Fstatic\u002Fcontent\u002Fimages\u002F2026\u002F11\u002FScrape-Indeed-Jobs.webp","2026-11-30T09:37:05.000Z","indeed job scraper",{"name":21,"slug":21},[128,129],{"name":21,"slug":21,"visibility":22},{"name":30,"slug":31,"visibility":22},[131,146,158,170,182],{"id":132,"title":133,"slug":134,"feature_image":135,"published_at":136,"twitter_title":137,"primary_tag":138,"tags":139},"6aa1292f4956c90001bef44e","ProxySite.com Review (2026): Is It Safe? 5 Best Alternatives","proxysite-review-alternatives","https:\u002F\u002Frola-ip.co\u002Fstatic\u002Fcontent\u002Fimages\u002F2026\u002F09\u002FProxySite-Review-and--Alternatives-article-cover-image.webp","2026-09-09T10:16:50.000Z","proxysite",{"name":21,"slug":21},[140,141,144],{"name":21,"slug":21,"visibility":22},{"name":142,"slug":143,"visibility":22},"对比选型","comparisons",{"name":145,"slug":145,"visibility":22},"hot",{"id":147,"title":148,"slug":149,"feature_image":150,"published_at":151,"twitter_title":152,"primary_tag":153,"tags":154},"6a978f9a4956c90001bee8bb","BlockAway Alternatives: 6 Best Options (2026)","blockaway-alternatives","https:\u002F\u002Frola-ip.co\u002Fstatic\u002Fcontent\u002Fimages\u002F2026\u002F09\u002FBlockAway-Alternatives-article-cover-image.webp","2026-09-02T03:14:08.000Z","blockaway alternative",{"name":21,"slug":21},[155,156,157],{"name":21,"slug":21,"visibility":22},{"name":142,"slug":143,"visibility":22},{"name":145,"slug":145,"visibility":22},{"id":159,"title":160,"slug":161,"feature_image":162,"published_at":163,"twitter_title":164,"primary_tag":165,"tags":166},"6a912ce84956c90001bee35d","HTTPX vs Requests vs aiohttp: Features, Performance, and Python Use Cases","httpx-vs-requests-vs-aiohttp","https:\u002F\u002Frola-ip.co\u002Fstatic\u002Fcontent\u002Fimages\u002F2026\u002F08\u002FHTTPX-vs-Requests-vs-aiohttp-article-cover-image.webp","2026-08-28T07:27:34.000Z","httpx vs requests",{"name":21,"slug":21},[167,168,169],{"name":21,"slug":21,"visibility":22},{"name":142,"slug":143,"visibility":22},{"name":145,"slug":145,"visibility":22},{"id":171,"title":172,"slug":173,"feature_image":174,"published_at":175,"twitter_title":176,"primary_tag":177,"tags":178},"6a90fcea4956c90001bee256","8 Best Germany Proxies in 2026: Provider Comparison","best-germany-proxies","https:\u002F\u002Frola-ip.co\u002Fstatic\u002Fcontent\u002Fimages\u002F2026\u002F08\u002FBest-Germany-Proxies-article-cover-image.webp","2026-08-28T03:40:55.000Z","germany proxy",{"name":21,"slug":21},[179,180,181],{"name":21,"slug":21,"visibility":22},{"name":142,"slug":143,"visibility":22},{"name":145,"slug":145,"visibility":22},{"id":183,"title":184,"slug":185,"feature_image":186,"published_at":187,"twitter_title":188,"primary_tag":189,"tags":190},"6a8e92664956c90001beddc2","Bing Rank Tracker: Reliable Local SERP Monitoring Guide","bing-rank-tracker","https:\u002F\u002Frola-ip.co\u002Fstatic\u002Fcontent\u002Fimages\u002F2026\u002F08\u002F-------16.webp","2026-08-26T07:42:04.000Z","bing rank checker",{"name":21,"slug":21},[191,192,195],{"name":21,"slug":21,"visibility":22},{"name":193,"slug":194,"visibility":22},"应用场景","use-cases",{"name":145,"slug":145,"visibility":22},[197,208,219,230,243],{"id":198,"title":199,"slug":200,"feature_image":201,"published_at":202,"twitter_title":203,"primary_tag":204,"tags":205},"6b0e31bf92ab700001dc0ae6","Proxyium Review: Is It Safe? Pros, Cons and Alternatives","proxyium-review","https:\u002F\u002Frola-ip.co\u002Fstatic\u002Fcontent\u002Fimages\u002F2026\u002F12\u002FProxyium-Review.webp","2026-12-01T02:56:52.000Z","Proxyium proxy",{"name":21,"slug":21},[206,207],{"name":21,"slug":21,"visibility":22},{"name":142,"slug":143,"visibility":22},{"id":209,"title":210,"slug":211,"feature_image":212,"published_at":213,"twitter_title":214,"primary_tag":215,"tags":216},"6b0d2bcb92ab700001dc0a12","Node.js HTTP Proxy Tutorial: Send HTTPS Requests with Rola IP and Verify the Exit IP","node-js-http-proxy","https:\u002F\u002Frola-ip.co\u002Fstatic\u002Fcontent\u002Fimages\u002F2026\u002F11\u002FNode.js-HTTP-Proxy-Tutorial_-Send-HTTPS-Requests-with-Rola-IP-and-Verify-the-Exit-IP.webp","2026-11-30T07:58:57.000Z","node js http proxy",{"name":21,"slug":21},[217,218],{"name":21,"slug":21,"visibility":22},{"name":30,"slug":31,"visibility":22},{"id":220,"title":221,"slug":222,"feature_image":223,"published_at":224,"twitter_title":225,"primary_tag":226,"tags":227},"6b09485d92ab700001dc0953","How to Set Up Chrome DevTools MCP for Multi-Region Geo-Testing with Residential Proxies","chrome-devtools-mcp-proxy-setup","https:\u002F\u002Frola-ip.co\u002Fstatic\u002Fcontent\u002Fimages\u002F2026\u002F11\u002Fchrome-devtools-mcp-proxy-setup.webp","2026-11-27T09:22:44.000Z","chrome-devtools-mcp proxy setup",{"name":21,"slug":21},[228,229],{"name":21,"slug":21,"visibility":22},{"name":30,"slug":31,"visibility":22},{"id":231,"title":232,"slug":233,"feature_image":234,"published_at":235,"twitter_title":236,"primary_tag":237,"tags":238},"6b0946f492ab700001dc0920","Best Rotating Proxies in 2026 7 Rotating Proxy Providers Compared","best-rotating-proxies","https:\u002F\u002Frola-ip.co\u002Fstatic\u002Fcontent\u002Fimages\u002F2026\u002F11\u002FBest-Rotating-Proxies-in-2026-7-Rotating-Proxy-Providers-Compared.webp","2026-11-27T09:07:09.000Z","best rotating proxies",{"name":21,"slug":21},[239,240],{"name":21,"slug":21,"visibility":22},{"name":241,"slug":242,"visibility":22},"排行榜","top-picks",{"id":244,"title":245,"slug":246,"feature_image":247,"published_at":248,"twitter_title":249,"primary_tag":250,"tags":251},"6b07a50492ab700001dc0603","How to Configure an NGINX Docker Reverse Proxy with Rola IP Egress","nginx-docker-reverse-proxy","https:\u002F\u002Frola-ip.co\u002Fstatic\u002Fcontent\u002Fimages\u002F2026\u002F11\u002FHow-to-Configure-an-NGINX-Docker-Reverse-Proxy-with-Rola-IP-Egress-1.webp","2026-11-26T03:21:51.000Z","nginx docker reverse proxy",{"name":21,"slug":21},[252,253],{"name":21,"slug":21,"visibility":22},{"name":30,"slug":31,"visibility":22}]