Note: The timeout parameter does not prevent the request from loading forever, it only stops if the remote server fails to send response data within the timeout value. It could still load indefinitely.

Set the timeout parameter:

try:
    r = requests.get("example.com", timeout=10) # 10 seconds
except requests.exceptions.Timeout:
    print("Timed out")

The code above will cause the call to requests.get() to timeout if the connection or delays between reads takes more than ten seconds.

The timeout parameter accepts the number of seconds to wait as a float, as well as a (connect timeout, read timeout) tuple.

See requests.request documentation as well as the timeout section of the "Advanced Usage" section of the documentation.

Answer from Lukasa on Stack Overflow
🌐
Pingproxies
pingproxies.com › blog › python-requests-timeout-techniques-for-stability
Python Requests Timeout: Guide to Stable HTTP Requests | Ping Proxies
January 20, 2026 - Sessions let you set a default timeout for all requests. However, Python's requests.Session() doesn't have a built-in way to set a default timeout.
Discussions

Timeout in requests.get
Hi, I was working with “requests.get” method to call an api. I have observed some instances where even after setting timeout thresholds in this method (read,connect or total), the requests sometimes doesn’t timeout within the mentioned range. Tried setting timeout parameter in requests.get, ... More on discuss.python.org
🌐 discuss.python.org
2
0
March 19, 2025
Why Does My Python POST Request Keep Timing Out?
What User-Agent header is being sent with Postman? Perhaps the default requests one is being blocked. More on reddit.com
🌐 r/learnpython
11
3
November 30, 2024
requests.get() timeout
After some trial and error I found it's your user agent, this should work import requests headers = { 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.77 Safari/537.36', } response = requests.get('https://www.bestbuy.com/', headers=headers) response.status_code More on reddit.com
🌐 r/learnpython
8
1
May 26, 2021
Python Requests - Hanging Requests despite setting Timeout Value

off the top of my head i think the issue is that you are only handling a small set of exceptions. If the try never completes and it is not one of your defined exceptions it will never break.

I would add the a generic except at the end to show you what else it may be breaking. And I would but a finally statement after that to output something useful to see if it is looping are blocking.

More on reddit.com
🌐 r/Python
8
0
April 22, 2019
🌐
Requests
requests.readthedocs.io › en › latest › user › advanced
Advanced Usage — Requests 2.33.1 documentation
The connect timeout is the number of seconds Requests will wait for your client to establish a connection to a remote machine (corresponding to the connect()) call on the socket.
🌐
ReqBin
reqbin.com › code › python › 3zdpeao1 › python-requests-timeout-example
How do I set a timeout for Python Requests?
To set a timeout for the Python Requests library, you can pass the "timeout" parameter for GET, POST, PUT, HEAD, and DELETE methods. The "timeout" parameter allows you to select the maximum time (in seconds) for the request to complete.
🌐
Oxylabs
oxylabs.io › blog › python-requests-timeout
Guide to Handling Python Requests Timeout
The timeout parameter accepts a tuple where the first value is the connect timeout and the second is the read timeout; for example, requests.get(url, timeout=(5, 10)). This feature facilitates finer control of HTTP requests, providing you the ability to improve the responsiveness of your Python script under varying network conditions.
🌐
Python.org
discuss.python.org › python help
Timeout in requests.get - Python Help - Discussions on Python.org
March 19, 2025 - Hi, I was working with “requests.get” method to call an api. I have observed some instances where even after setting timeout thresholds in this method (read,connect or total), the requests sometimes doesn’t timeout within the mentioned range. Tried setting timeout parameter in requests.get, ...
🌐
Python Requests
python-requests.org › home › news › python requests timeout: a complete guide for developers
A Complete Guide for Developers - Python Requests Timeout
November 13, 2025 - In the Python Requests library, you can specify a timeout using the timeout parameter in most request methods, such as get(), post(), and put().
Find elsewhere
🌐
Codiga
codiga.io › blog › python-requests-timeout
Python Best Practices: always use a timeout with the requests library
To overcome this issue, the best way is to set a timeout in the requests.get or requests.put call. If the timeout occurs, a TimeoutException needs to be correctly handled.
🌐
ProxyWing
proxywing.com › home › blog › python requests timeout: how to set, handle, and optimize it
Python Requests Timeout: Fix Hanging HTTP Calls Fast
October 30, 2025 - A Python request timeout defines the amount of time a client waits for a response from a server. These timeouts sessions get two different phases, which include a connection phase as well as a read phase.
🌐
iProyal
iproyal.com › blog › python-requests-timeout
How to Use Timeout with Python Requests (With Examples)
November 24, 2025 - You can add the timeout parameter to any request method, like GET or POST . It tells the Python Requests library how long to wait before timing out.
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-requests-readtimeout-error
Python Requests Readtimeout Error - GeeksforGeeks
July 23, 2025 - The ReadTimeout error in Python's requests library typically occurs when a request takes longer to complete than the specified timeout duration.
🌐
Quora
quora.com › How-do-I-increase-the-request-timeout-in-Python
How to increase the request timeout in Python - Quora
Use the pattern appropriate to your library: set per-request timeouts when possible, prefer explicit connect/read/total distinctions, and combine with retries/backoff for production resilience. ... What should I use, Go or Python for sending HTTP requests so that once a request is sent, it will send another if a specific result is gotten from it?
🌐
Better Stack
betterstack.com › community › guides › scaling-python › python-timeouts
A Complete Guide to Timeouts in Python | Better Stack Community
Python offers several libraries for making HTTP requests, with requests being the most popular. The requests library doesn't set a default timeout, meaning your requests could hang indefinitely.
🌐
Findwork
findwork.dev › blog › advanced-usage-python-requests-timeouts-retries-hooks
Advanced usage of Python requests - timeouts, retries, hooks
February 28, 2020 - We override the constructor to provide a default timeout when constructing the http client and the send() method to ensure that the default timeout is used if a timeout argument isn't provided. from requests.adapters import HTTPAdapter DEFAULT_TIMEOUT = 5 # seconds class TimeoutHTTPAdapter(HTTPAdapter): def __init__(self, *args, **kwargs): self.timeout = DEFAULT_TIMEOUT if "timeout" in kwargs: self.timeout = kwargs["timeout"] del kwargs["timeout"] super().__init__(*args, **kwargs) def send(self, request, **kwargs): timeout = kwargs.get("timeout") if timeout is None: kwargs["timeout"] = self.timeout return super().send(request, **kwargs)
🌐
Apify
blog.apify.com › python-requests-timeout
How to handle timeouts in Python Requests
May 26, 2025 - A tutorial that shows you how to connect and read timeouts, handle exceptions, and use timeouts with sessions and in a multithreaded environment.
🌐
Reddit
reddit.com › r/learnpython › why does my python post request keep timing out?
r/learnpython on Reddit: Why Does My Python POST Request Keep Timing Out?
November 30, 2024 -

I’m testing an API using Python's requests library but keep running into a Timeout error: "Request timed out", even though the same setup works fine in Postman.

import requests

url = "https://api.example.com/endpoint"
headers = {
    "Key1": "value1",
    "Key2": "value2",
    "Cookie": "CSToken=the actual token"
}

try:
    response = requests.post(url, headers=headers, json=payload, timeout=10)
    print(response.status_code)
    print(response.text)
except requests.exceptions.Timeout:
    print("Request timed out")
except requests.exceptions.RequestException as e:
    print(f"Error: {e}")

Questions:

  1. Could there be additional settings or implicit headers in Postman I’m missing in Python?

  2. What steps can I take to debug or resolve this issue?

Any help is greatly appreciated. Thank you!

What I Tried: I sent a POST request to the API using Python's requests library, including the Cookie header with the authentication token, as done in Postman.

What I Expected: I expected the API to return the same successful response it does in Postman.

What Actually Happened: The request timed out, raising a Timeout exception in Python, even though it works without issues in Postman.

🌐
MarsProxies
marsproxies.com › blog › python-requests-timeout
How to Use Python Requests Timeouts
The time interval that your browser waits for the server to respond is the timeout parameter. The Python Requests library lets you set two timeout parameters. You will use the connect timeout parameter to define how long your application must ...
🌐
ProxiesAPI
proxiesapi.com › articles › how-to-handle-timeout-error-in-python-requests
How to Handle Timeout error in Python requests | ProxiesAPI
A timeout is a predefined time limit for a request to a server to complete. In the Python requests library, we set timeouts to prevent:
🌐
datagy
datagy.io › home › python requests › timeouts in python requests
Timeouts in Python requests • datagy
December 30, 2022 - In this tutorial, you’ll learn how to use timeouts in the Python requests library, when working with any type of HTTP request being made. By default, the requests library will not time out any request you make, which can result in your programming ...
🌐
Requests
requests.readthedocs.io › en › latest › user › quickstart
Quickstart — Requests 2.33.1 documentation
You can tell Requests to stop waiting for a response after a given number of seconds with the timeout parameter. Nearly all production code should use this parameter in nearly all requests.