Skip to content

Commit 114958e

Browse files
authored
Merge pull request #1895 from python-gitlab/jlvillal/rate-limit
fix: support RateLimit-Reset header
2 parents 363bc87 + 4060146 commit 114958e

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

gitlab/client.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -700,10 +700,14 @@ def http_request(
700700
if (429 == result.status_code and obey_rate_limit) or (
701701
result.status_code in [500, 502, 503, 504] and retry_transient_errors
702702
):
703+
# Response headers documentation:
704+
# https://docs.gitlab.com/ee/user/admin_area/settings/user_and_ip_rate_limits.html#response-headers
703705
if max_retries == -1 or cur_retries < max_retries:
704706
wait_time = 2**cur_retries * 0.1
705707
if "Retry-After" in result.headers:
706708
wait_time = int(result.headers["Retry-After"])
709+
elif "RateLimit-Reset" in result.headers:
710+
wait_time = int(result.headers["RateLimit-Reset"]) - time.time()
707711
cur_retries += 1
708712
time.sleep(wait_time)
709713
continue

0 commit comments

Comments
 (0)