diff options
author | Srikanth Chelluri <srikanth.chelluri@appian.com> | 2019-01-08 20:58:26 -0500 |
---|---|---|
committer | Srikanth Chelluri <srikanth.chelluri@appian.com> | 2019-01-08 21:54:09 -0500 |
commit | 7a3724f3fca93b4f55aed5132cf46d3718c4f594 (patch) | |
tree | 640200cc827b3c6f6fcf3b638bcc4e9ffcc696dc /docs/api-usage.rst | |
parent | ce2c8356cdd0e086ec67a1bf73adc2d0ea251971 (diff) | |
download | gitlab-7a3724f3fca93b4f55aed5132cf46d3718c4f594.tar.gz |
fix: handle empty 'Retry-After' header from GitLab
When requests are throttled (HTTP response code 429), python-gitlab
assumed that 'Retry-After' existed in the response headers. This is
not always the case and so the request fails due to a KeyError. The
change in this commit adds a rudimentary exponential backoff to the
'http_request' method, which defaults to 10 retries but can be set
to -1 to retry without bound.
Diffstat (limited to 'docs/api-usage.rst')
-rw-r--r-- | docs/api-usage.rst | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/docs/api-usage.rst b/docs/api-usage.rst index 73d1377..a5afbda 100644 --- a/docs/api-usage.rst +++ b/docs/api-usage.rst @@ -299,7 +299,9 @@ Rate limits python-gitlab obeys the rate limit of the GitLab server by default. On receiving a 429 response (Too Many Requests), python-gitlab sleeps for the -amount of time in the Retry-After header that GitLab sends back. +amount of time in the Retry-After header that GitLab sends back. If GitLab +does not return a response with the Retry-After header, python-gitlab will +perform an exponential backoff. If you don't want to wait, you can disable the rate-limiting feature, by supplying the ``obey_rate_limit`` argument. @@ -312,6 +314,18 @@ supplying the ``obey_rate_limit`` argument. gl = gitlab.gitlab(url, token, api_version=4) gl.projects.list(all=True, obey_rate_limit=False) +If you do not disable the rate-limiting feature, you can supply a custom value +for ``max_retries``; by default, this is set to 10. To retry without bound when +throttled, you can set this parameter to -1. This parameter is ignored if +``obey_rate_limit`` is set to ``False``. + +.. code-block:: python + + import gitlab + import requests + + gl = gitlab.gitlab(url, token, api_version=4) + gl.projects.list(all=True, max_retries=12) .. warning:: |