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
🌐
Requests
requests.readthedocs.io › en › latest › user › advanced
Advanced Usage — Requests 2.33.0 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.
Discussions

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
10
3
November 30, 2024
Python requests module connection timeout - Stack Overflow
I'm looking at http://docs.python-requests.org/en/latest/ and "Connection Timeouts" is listed as a feature. However, when I read further, it states timeout is not a time limit on the entire res... More on stackoverflow.com
🌐 stackoverflow.com
Setting session.timeout doesn't do anything
I was using an old version of requests (I don't know the exact version). When settings the session.timeout it was affecting the timeout value during a call to session.get(). With recent version of ... More on github.com
🌐 github.com
10
June 17, 2016
Is it still supported to set a request timeout for request?
Hi all, It seems supported to specify the timeout. However, that does not work I found this “timeout” and “request_timeout” but the income is unsupported values. Anyone have a reference about how to set the timeout? Thanks in advance More on community.openai.com
🌐 community.openai.com
1
1
January 2, 2025
🌐
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, ...
🌐
Requests
requests.readthedocs.io › en › latest › user › quickstart
Quickstart — Requests 2.33.0 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.
🌐
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.
🌐
Python Requests
python-requests.org › home › news › python requests timeout: a complete guide for developers
Python Requests Timeout: A Complete Guide for Developers
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
🌐
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.

🌐
Sourcery
sourcery.ai › vulnerabilities › python-requests-best-practice-use-timeout
Python Requests Missing Timeout Vulnerability | Security Vulnerability Database | Sourcery
Context-specific timeouts: quick API calls timeout=5; large downloads timeout=(5, 300); streaming timeout=(5, None) with manual chunking; health checks timeout=2. Match timeout to operation characteristics.
🌐
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.
🌐
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.
🌐
GitHub
github.com › psf › requests › issues › 3341
Setting session.timeout doesn't do anything · Issue #3341 · psf/requests
June 17, 2016 - I was using an old version of requests (I don't know the exact version). When settings the session.timeout it was affecting the timeout value during a call to session.get(). With recent version of requests, this feature doesn't seams to ...
Author   ikus060
🌐
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.
🌐
Scrapfly
scrapfly.io › blog › answers › python-requests-exception-readtimeout
How to fix Python requests ReadTimeout error? - Scrapfly Blog
December 19, 2022 - By default, the requests module has no timeout which can hang the whole program indefinitely so this value should always be set to 1-120 seconds depending on the target. If you're encountering a lot of ReadTimeout exceptions your scraper might ...
🌐
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?
🌐
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.
🌐
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 ...
🌐
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 ...
🌐
Reddit
reddit.com › r/learnpython › requests.get() timeout
r/learnpython on Reddit: requests.get() timeout
May 26, 2021 -

I don't understand why I don't get a response from Best Buy's website. I get a status code of 200 if I swap best buy's page out for Amazon's home page. Is it a 403 Error that I'm getting from Best Buy? All I see on my end is an error:

urllib3.exceptions.ReadTimeoutError: HTTPSConnectionPool(host='www.bestbuy.com', port=443): Read timed out. (read timeout=60)

I don't understand why I don't receive a status code, or something indicating what's happening after the request is sent. So I'm just sort of in the dark in how to proceed. I can use a different site to learn BeautifulSoup, but I'd love to know why this doesnt work. My code:

from bs4 import BeautifulSoup
import requests

headers = {'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/56.0.2924.76 Safari/537.36'}
response = requests.get(
'https://www.bestbuy.com', headers=headers, timeout=60)

print (response.status_code)