Feature Request: Pass Response to `Retry.is_retry()`
See original GitHub issueI’m working on some tools for using the Internet Archive’s Wayback Machine APIs and it’d be really helpful if I could write a custom Retry class that can look at the the response headers to determine whether a retry is warranted. In particular, when requesting the snapshot of a URL, it’s possible to get an error code that might be coming from the wayback machine or might be coming from the snapshot itself (i.e. the original URL returned the error code when it was scraped). You can determine which of these situations you’re dealing with by looking for the Memento-Datetime header, but Retry.is_retry(), which seems like the right place to do this, doesn’t have access to that info.
It feels like there ought to be plenty of other odd cases where more info about the response would be helpful, so I’m wondering if passing it directly to Retry.is_retry() would be a good idea. Since this gets called before Retry.increment() adds request info to the history, passing the URL might be nice, too.
I’d love to change this signature:
def is_retry(self, method, status_code, has_retry_after=False):
to:
def is_retry(self, method, url, response):
(status_code and has_retry_after can both be obtained from the response object, and can even be handled slightly more efficiently by not asking for them before they’re needed, since is_retry() returns early in some cases.)
Issue Analytics
- State:
- Created 5 years ago
- Reactions:1
- Comments:11 (4 by maintainers)

Top Related StackOverflow Question
At a minimum I’ll mark this as something for 2.0.0 because I agree that we should be passing the whole response into the
Retryobject to allow for better subclassing potential.Yep, the approach in #2500 would certainly work for my case.