Python requests module connection timeout

The timeout is used for both the socket connect stage and the response reading stage. The only exception is streamed requests; if you set stream=True, the timeout cannot be applied to the reading portion. The timeout is indeed used just for waiting for the socket to connect or data to be received.

If you need an overall timeout, then use another technique, like using interrupts or eventlets: Timeout for python requests.get entire response


The requests (for humans) library has connection timeouts, see - https://requests.kennethreitz.org/en/master/user/advanced/#timeouts

r = requests.get('https://github.com', timeout=(3.05, 27))

# e.g. explicitly
conn_timeout = 6
read_timeout = 60
timeouts = (conn_timeout, read_timeout)
r = requests.get('https://github.com', timeout=timeouts)

The docs are not exactly explicit about which value is which in the tuple, but it might be safe to assume that it's (connect, read) timeouts.