requests.{get,post} timeout

Skip Montanaro skip.montanaro at gmail.com
Tue Aug 22 10:02:15 EDT 2017


I'm using the requests module with timeouts to fetch URLs, for example:

    response = requests.get("http://www.google.com/", timeout=10)

I understand the timeout value in this case applies both to creating the
connection and fetching the remote content. Can the server dribble out the
content (say, one byte every few seconds) to avoid triggering the timeout,
or must the request be completed within ten seconds after the connection is
successfully opened? My reading of the documentation here is inconclusive:

http://docs.python-requests.org/en/master/user/advanced/#timeouts

    If you specify a single value for the timeout, like this:

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

    The timeout value will be applied to both the connect and the read
timeouts.

Does "read timeout" imply the timeout applied to an individual read from
the underlying socket? A quick glance at the code suggests that might be
the case, but I got a bit lost in the urllib3 code which underpins the
requests module.

Thx,

Skip



More information about the Python-list mailing list