Skip to content

Commit

Permalink
Merge pull request #1895 from python-gitlab/jlvillal/rate-limit
Browse files Browse the repository at this point in the history
fix: support RateLimit-Reset header
  • Loading branch information
nejch committed Mar 10, 2022
2 parents 363bc87 + 4060146 commit 114958e
Showing 1 changed file with 4 additions and 0 deletions.
4 changes: 4 additions & 0 deletions gitlab/client.py
Expand Up @@ -700,10 +700,14 @@ def http_request(
if (429 == result.status_code and obey_rate_limit) or (
result.status_code in [500, 502, 503, 504] and retry_transient_errors
):
# Response headers documentation:
# https://docs.gitlab.com/ee/user/admin_area/settings/user_and_ip_rate_limits.html#response-headers
if max_retries == -1 or cur_retries < max_retries:
wait_time = 2**cur_retries * 0.1
if "Retry-After" in result.headers:
wait_time = int(result.headers["Retry-After"])
elif "RateLimit-Reset" in result.headers:
wait_time = int(result.headers["RateLimit-Reset"]) - time.time()
cur_retries += 1
time.sleep(wait_time)
continue
Expand Down

0 comments on commit 114958e

Please sign in to comment.