7

I've been reading through http://www.mobify.com/blog/http-requests-are-hard/ and http://docs.python-requests.org/en/latest/api/#requests.request to understand timeouts better. based on this I can see that there are connect timeouts:

connect_timeout = 0.0001

try:
    response = requests.get(url="https://httpbin.org/delay/5",
                        timeout=(connect_timeout, 10.0))
except requests.exceptions.ConnectTimeout as e:
    print "Too slow Mojo!"

and read timeouts:

read_timeout = 1.0

try:
    response = requests.get(url="https://httpbin.org/delay/5",
                        timeout=(10.0, read_timeout))
except requests.exceptions.ReadTimeout as e:
    print "Waited too long between bytes."

I'm also interested in having the requests module "give up" if the response is not completed within a specific time. I'm not sure what the term for this kind of timeout is. How would i make this happen?

user1592380
  • 34,265
  • 92
  • 284
  • 515
  • 1
    What's the difference between what your last sentence is asking for and the first kind of timeout you describe? – Two-Bit Alchemist Aug 27 '15 at 20:06
  • 1
    As far as I understand from the blog article, a connect timeout refers to how long the client waits for the initial connection, whereas I'm asking for for a timeout from the initial request after the connection is made until the response is complete – user1592380 Aug 27 '15 at 21:55
  • 1
    possible duplicate of [Timeout for python requests.get entire response](http://stackoverflow.com/questions/21965484/timeout-for-python-requests-get-entire-response) – Two-Bit Alchemist Aug 28 '15 at 15:04
  • 1
    The requests library does not provide an overall timeout for a request. [This comment](https://github.com/requests/requests/issues/3099#issuecomment-215498005) from a requests developer has a good explanation of why requests does not have a total-response-time timeout, and what they suggest instead. – Christian Long Sep 14 '18 at 14:16

0 Answers0