psf / requests

A simple, yet elegant, HTTP library.
https://requests.readthedocs.io/en/latest/
Apache License 2.0
52.19k stars 9.33k forks source link

Add default timeout #6709

Open sigmavirus24 opened 6 months ago

sigmavirus24 commented 6 months ago

This adds a default connect and read timeout value for all usage of Requests. This is to solve a long-standing issue where some systems do not have a sufficiently low default value.

Personally, I'd want these values to be much lower, but a 10 second connection timeout and a 30 second read timeout seem like they should be enough to avoid problems for the edge cases of users while also not being so large that they're basically ineffective.

Closes #3070

cmyers009 commented 2 months ago

If you add a default timeout it may break existing code bases.

For example, if I am using a GET request to download a 1 GB file then I would have to adjust timeout to make my code compatible with this proposed change.

sigmavirus24 commented 2 months ago

If you add a default timeout it may break existing code bases.

For example, if I am using a GET request to download a 1 GB file then I would have to adjust timeout to make my code compatible with this proposed change.

You don't understand timeouts in Python. Please go read any number of past issues and blog posts about this issue before spreading FUD.

neochine commented 4 weeks ago

Consider also adding -1 as timeout value such that it retains wait till infinity as requests currently behaves. That behaviour is desirable ValueError: Attempted to set connect timeout to -1, but the timeout cannot be set to a value less than or equal to 0.

if timeout is None:
   timeout = _DEFAULT_TIMEOUT
if timeout == -1:
   timeout = None
# causes default timeout if not passed, if -1 is passed it becomes None, else if any other number is passed it becomes timeout after that much seconds