@@ -451,6 +451,10 @@ def http_request(
451
451
post_data : Optional [Dict [str , Any ]] = None ,
452
452
streamed : bool = False ,
453
453
files : Optional [Dict [str , Any ]] = None ,
454
+ timeout : Optional [float ] = None ,
455
+ obey_rate_limit : bool = True ,
456
+ retry_transient_errors : bool = False ,
457
+ max_retries : int = 10 ,
454
458
** kwargs : Any ,
455
459
) -> requests .Response :
456
460
"""Make an HTTP request to the Gitlab server.
@@ -465,6 +469,14 @@ def http_request(
465
469
json)
466
470
streamed (bool): Whether the data should be streamed
467
471
files (dict): The files to send to the server
472
+ timeout (float): The timeout, in seconds, for the request
473
+ obey_rate_limit (bool): Whether to obey 429 Too Many Request
474
+ responses. Defaults to True.
475
+ retry_transient_errors (bool): Whether to retry after 500, 502,
476
+ 503, or 504 responses. Defaults
477
+ to False.
478
+ max_retries (int): Max retries after 429 or transient errors,
479
+ set to -1 to retry forever. Defaults to 10.
468
480
**kwargs: Extra options to send to the server (e.g. sudo)
469
481
470
482
Returns:
@@ -496,9 +508,10 @@ def http_request(
496
508
opts = self ._get_session_opts (content_type = "application/json" )
497
509
498
510
verify = opts .pop ("verify" )
499
- timeout = opts .pop ("timeout" )
511
+ opts_timeout = opts .pop ("timeout" )
500
512
# If timeout was passed into kwargs, allow it to override the default
501
- timeout = kwargs .get ("timeout" , timeout )
513
+ if timeout is None :
514
+ timeout = opts_timeout
502
515
503
516
# We need to deal with json vs. data when uploading files
504
517
if files :
@@ -532,15 +545,7 @@ def http_request(
532
545
prepped .url , {}, streamed , verify , None
533
546
)
534
547
535
- # obey the rate limit by default
536
- obey_rate_limit = kwargs .get ("obey_rate_limit" , True )
537
- # do not retry transient errors by default
538
- retry_transient_errors = kwargs .get ("retry_transient_errors" , False )
539
-
540
- # set max_retries to 10 by default, disable by setting it to -1
541
- max_retries = kwargs .get ("max_retries" , 10 )
542
548
cur_retries = 0
543
-
544
549
while True :
545
550
result = self .session .send (prepped , timeout = timeout , ** settings )
546
551
@@ -827,6 +832,9 @@ def __init__(
827
832
self ._query (url , query_data , ** self ._kwargs )
828
833
self ._get_next = get_next
829
834
835
+ # Remove query_parameters from kwargs, which are saved via the `next` URL
836
+ self ._kwargs .pop ("query_parameters" , None )
837
+
830
838
def _query (
831
839
self , url : str , query_data : Optional [Dict [str , Any ]] = None , ** kwargs : Any
832
840
) -> None :
0 commit comments