Skip to content

Commit

Permalink
chore: handles non number rate_limit_reset header
Browse files Browse the repository at this point in the history
  • Loading branch information
a-rampalli committed Dec 26, 2023
1 parent 2da69f0 commit b8845d8
Showing 1 changed file with 7 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,13 @@ def backoff_time(self, response: requests.Response) -> float:
response_headers = response.headers
RATE_LIMIT_RESET_HEADER = "x-ratelimit-reset"
if RATE_LIMIT_RESET_HEADER in response_headers:
# Assumes it is a number
sleep_time = int(response_headers.get(RATE_LIMIT_RESET_HEADER)) + 1
self.logger.info(f"Rate limit exceeded. Sleeping for {sleep_time} seconds")
return sleep_time
try:
sleep_time = int(response_headers.get(RATE_LIMIT_RESET_HEADER)) + 1
self.logger.info(f"Rate limit exceeded. Sleeping for {sleep_time} seconds")
return sleep_time
except ValueError:
# Log error and use default exponential backoff
self.logger.error(f"Rate limit reset header value is not a number. Value: {response_headers.get(RATE_LIMIT_RESET_HEADER)}")
# Use default exponential backoff if rate limit headers are not present
return super().backoff_time(response)

Expand Down

0 comments on commit b8845d8

Please sign in to comment.