Repository navigation
feat: expose Retry-After in APIError - #230
Draft
gracehopper-vt wants to merge 2 commits into
Draft
gracehopper-vt wants to merge 2 commits into
gracehopper-vt wants to merge 2 commits into
Conversation
The VirusTotal API is starting to send a Retry-After header with rate-limit and quota-exceeded responses. Parse it (either seconds or an HTTP date) and expose it as APIError.retry_after so callers can wait the right amount of time before retrying. It is None when the header is not present. Co-authored-by: Oscar Torreno <torreno@google.com>
Co-authored-by: Oscar Torreno <torreno@google.com>
This branch has not been deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
The VirusTotal API is adding a
Retry-Afterheader to rate-limit / quota-exceeded responses (429in API v3). This PR makes it available to vt-py users:APIErrorgets a new optionalretry_afterattribute (seconds,int),Nonewhen the response has noRetry-Afterheader.Client.get_error_asyncparses the header, accepting both forms allowed by RFC 9110: delta-seconds (Retry-After: 120) and an HTTP date.APIError(code, message)andAPIError.from_dict(error)keep working, andargsis unchanged.Usage:
No automatic retries are added: when a daily or monthly quota is exhausted,
retry_aftercan be hours or days, and silently sleeping that long would hang scripts. Automatic waiting could be added later as an opt-in.Tests
New tests in
tests/test_client.pyfor a 429 withRetry-Afterin seconds, a 429 with an HTTP-dateRetry-After, and an error without the header. Full suite: 45 passed.