Python2 HTTPAdapter: How to Handle Persistent Connections and Timeouts Effectively?

18 Replies, 1674 Views

Python2 HTTPAdapter is a pain, no doubt. For timeouts, I’ve had some luck with using `requests` and setting `timeout=(connect_timeout, read_timeout)` explicitly. It’s not foolproof, but it’s better than nothing.

For persistent connections, try using `requests.Session()` and manually closing the session after a certain number of requests. It’s a bit of a hack, but it works.

Also, if you’re dealing with a lot of retries, consider using `tenacity` for custom retry logic.

Messages In This Thread



Users browsing this thread: 1 Guest(s)