top | item 22442746

Advanced usage of Python requests: timeouts, retries, hooks

123 points| dhxt | 6 years ago |findwork.dev

11 comments

order
[+] inetknght|6 years ago|reply
I just recently dealt with a timeout issue in requests: I was setting the timeout to 1 but it took 10 seconds for the request to fail. It turns out that the timeout does not apply to the name resolver and the name lookup was timing out. So the default system-level timeout was 10 seconds.
[+] hmhrex|6 years ago|reply
Thank you for this brief reference. I'm always going back to my old projects to remind myself how I did things with requests. I didn't realize some of things existed.
[+] sciurus|6 years ago|reply
I wish that requests had a default timeout instead of defaulting to waiting forever.

It's very easy for devs to forget to think about timeouts, but inevitably that ends in a cascading production outage.

[+] jakeogh|6 years ago|reply
If I enable logging of retries: logging.basicConfig(level=logging.DEBUG)

I dont see any retries on response 200: ConnectionError(ReadTimeoutError("HTTPSConnectionPool(host='domain.com', port=443): Read timed out."))

Is there a way to also retry on ChunkedEncodingError?

[+] ddeokbokki|6 years ago|reply
That sentry responses decorator is absolutely beautiful
[+] da12|6 years ago|reply
Fantastic reference. Thanks for sharing!