diff --git a/docs/api-usage-advanced.rst b/docs/api-usage-advanced.rst index d6514c7b3..d8ed4a1f1 100644 --- a/docs/api-usage-advanced.rst +++ b/docs/api-usage-advanced.rst @@ -147,7 +147,8 @@ python-gitlab can automatically retry in such case, when ``retry_transient_errors`` argument is set to ``True``. When enabled, HTTP error codes 500 (Internal Server Error), 502 (502 Bad Gateway), 503 (Service Unavailable), 504 (Gateway Timeout), and Cloudflare -errors (520-530) are retried. +errors (520-530) are retried. `requests.exceptions.Timeout` are also +handled. Additionally, HTTP error code 409 (Conflict) is retried if the reason is a diff --git a/gitlab/client.py b/gitlab/client.py index ea3a0c209..8616ef3cc 100644 --- a/gitlab/client.py +++ b/gitlab/client.py @@ -60,7 +60,7 @@ class Gitlab: order_by: Set order_by globally user_agent: A custom user agent to use for making HTTP requests. retry_transient_errors: Whether to retry after 500, 502, 503, 504 - or 52x responses. Defaults to False. + or 52x responses, or after a request timeout. Defaults to False. keep_base_url: keep user-provided base URL for pagination if it differs from response headers @@ -665,7 +665,7 @@ def http_request( obey_rate_limit: Whether to obey 429 Too Many Request responses. Defaults to True. retry_transient_errors: Whether to retry after 500, 502, 503, 504 - or 52x responses. Defaults to False. + or 52x responses, or after a request timeout. Defaults to False. max_retries: Max retries after 429 or transient errors, set to -1 to retry forever. Defaults to 10. extra_headers: Add and override HTTP headers for the request. @@ -737,7 +737,11 @@ def http_request( stream=streamed, **opts, ) - except (requests.ConnectionError, requests.exceptions.ChunkedEncodingError): + except ( + requests.ConnectionError, + requests.exceptions.ChunkedEncodingError, + requests.exceptions.Timeout, + ): if retry.handle_retry(): continue raise diff --git a/tests/unit/test_gitlab_http_methods.py b/tests/unit/test_gitlab_http_methods.py index f85035fc2..00d96d0be 100644 --- a/tests/unit/test_gitlab_http_methods.py +++ b/tests/unit/test_gitlab_http_methods.py @@ -146,6 +146,7 @@ def test_http_request_extra_headers(gl): [ requests.ConnectionError("Connection aborted."), requests.exceptions.ChunkedEncodingError("Connection broken."), + requests.exceptions.Timeout("Request timed out."), ], ) def test_http_request_with_retry_on_method_for_transient_network_failures(