requests.{get,post} timeout

Chris Angelico rosuav at gmail.com
Tue Aug 22 13:08:33 EDT 2017


On Wed, Aug 23, 2017 at 2:58 AM, Jon Ribbens <jon+usenet at unequivocal.eu> wrote:
> On 2017-08-22, 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,
>
> Yes. There is no timeout feature that can be used to limit the total
> time a 'requests' request takes. Some people might think that this is
> a serious flaw in the requests library that would need urgent
> rectification in order to make the library safe and useful to use in
> almost any situation, but the 'requests' developers are apparently not
> among those people.

I'm not either. The idea of a timeout is to detect when something's
completely not working, not to limit the overall time to process. If
you want that, you can do it locally, maybe with signal.alarm or a
thread or something.

ChrisA



More information about the Python-list mailing list