@@ -52,6 +52,8 @@ class Gitlab(object):
5252 pagination (str): Can be set to 'keyset' to use keyset pagination
5353 order_by (str): Set order_by globally
5454 user_agent (str): A custom user agent to use for making HTTP requests.
55+ retry_transient_errors (bool): Whether to retry after 500, 502, 503, or
56+ 504 responses. Defaults to False.
5557 """
5658
5759 def __init__ (
@@ -70,6 +72,7 @@ def __init__(
7072 pagination : Optional [str ] = None ,
7173 order_by : Optional [str ] = None ,
7274 user_agent : str = gitlab .const .USER_AGENT ,
75+ retry_transient_errors : bool = False ,
7376 ) -> None :
7477
7578 self ._api_version = str (api_version )
@@ -79,6 +82,7 @@ def __init__(
7982 self ._url = "%s/api/v%s" % (self ._base_url , api_version )
8083 #: Timeout to use for requests to gitlab server
8184 self .timeout = timeout
85+ self .retry_transient_errors = retry_transient_errors
8286 #: Headers that will be used in request to GitLab
8387 self .headers = {"User-Agent" : user_agent }
8488
@@ -511,7 +515,6 @@ def http_request(
511515 files : Optional [Dict [str , Any ]] = None ,
512516 timeout : Optional [float ] = None ,
513517 obey_rate_limit : bool = True ,
514- retry_transient_errors : bool = False ,
515518 max_retries : int = 10 ,
516519 ** kwargs : Any ,
517520 ) -> requests .Response :
@@ -531,9 +534,6 @@ def http_request(
531534 timeout (float): The timeout, in seconds, for the request
532535 obey_rate_limit (bool): Whether to obey 429 Too Many Request
533536 responses. Defaults to True.
534- retry_transient_errors (bool): Whether to retry after 500, 502,
535- 503, or 504 responses. Defaults
536- to False.
537537 max_retries (int): Max retries after 429 or transient errors,
538538 set to -1 to retry forever. Defaults to 10.
539539 **kwargs: Extra options to send to the server (e.g. sudo)
@@ -598,6 +598,9 @@ def http_request(
598598 if 200 <= result .status_code < 300 :
599599 return result
600600
601+ retry_transient_errors = kwargs .get (
602+ "retry_transient_errors" , self .retry_transient_errors
603+ )
601604 if (429 == result .status_code and obey_rate_limit ) or (
602605 result .status_code in [500 , 502 , 503 , 504 ] and retry_transient_errors
603606 ):
0 commit comments