Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: How to handle dynamically changing retry (think api throttling) #461

Open
ravensorb opened this issue May 14, 2024 · 2 comments
Open

Comments

@ravensorb
Copy link

I am curious if there is a way to handle dynamically change the retry wait period based on something that happens within the process being executed. The specific example I have is an API that has a rate limit on it and it returns in the HTTP headers the recommended amount of time to wait before retying the call.

Any thoughts or suggestions on how to approach?

@ahgraber
Copy link

I'm also interested in this!

@basilisk487
Copy link

basilisk487 commented Sep 24, 2024

you can use a custom wait callback:

def my_wait(retry_state: RetryCallState):
    ex = retry_state.outcome.exception()
    if isinstance(ex, requests.exceptions.HTTPError) and ex.response.status_code == 429:
        retry_after = ex.response.headers.get("Retry-After")
        try:
            return int(retry_after)
        except (TypeError, ValueError):
            pass
    return 0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants