python – HTTP timeout

python – HTTP timeout

Use the timeout parameter:

r =, data=payload, timeout=1.5)

Note: timeout is not a time limit on the entire response download;
rather, an exception is raised if the server has not issued a response
for timeout seconds (more precisely, if no bytes have been received on
the underlying socket for timeout seconds). If no timeout is specified
explicitly, requests do not time out.

All requests take a timeout keyword argument. 1

The is simplify forwarding its arguments to requests.request 2

When the app is down, there is more likelihood of a ConnectionError than a Timeout. 3

try:, data=payload, timeout=5)
except requests.Timeout:
    # back off and retry
except requests.ConnectionError:

python – HTTP timeout

Leave a Reply

Your email address will not be published. Required fields are marked *