When making HTTP requests in Python using the requests library, timeouts are set by default to prevent requests from running indefinitely. However, sometimes you may want to intentionally make a request without any timeout.
Why Remove the Timeout?
There are a few reasons why you may want to remove the timeout on a request:
Removing the timeout introduces the risk of requests getting stuck, so only do this if you understand the tradeoffs.
To make a request without timeout, you simply need to set the
response = requests.get('http://example.com/report', timeout=None)
You can also set this at the session level to apply the setting to all requests made with that session:
session = requests.Session()
session.timeout = None
response = session.get('http://example.com/report')
By understanding the tradeoffs and being careful about where you remove timeouts, you can use this approach to let long requests run to completion when needed in Python.