Timeouts

You can tell Requests to stop waiting for a response after a given number of seconds with the timeout parameter:

  1. >>> requests.get('http://github.com', timeout=0.001)
  2. Traceback (most recent call last):
  3. File "<stdin>", line 1, in <module>
  4. requests.exceptions.Timeout: HTTPConnectionPool(host='github.com', port=80): Request timed out. (timeout=0.001)

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).