requests.{get,post} timeout

Chris Angelico rosuav at gmail.com
Tue Aug 22 12:52:44 EDT 2017


On Wed, Aug 23, 2017 at 12:02 AM, Skip Montanaro
<skip.montanaro at gmail.com> wrote:
> 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.

"""
Once your client has connected to the server and sent the HTTP
request, the read timeout is the number of seconds the client will
wait for the server to send a response. (Specifically, it's the number
of seconds that the client will wait between bytes sent from the
server. In 99.9% of cases, this is the time before the server sends
the first byte).
"""

"Between bytes" implies that you could have a long request, as long as
there's a keep-alive transmission every few seconds.

ChrisA



More information about the Python-list mailing list