From 85e8a3be1cfeb7356040f491ac94dc25113a3599 Mon Sep 17 00:00:00 2001 From: Daniel Mach Date: Tue, 12 Mar 2024 17:31:32 +0100 Subject: [PATCH] Revert "connection: Allow disabling retry on 400 HTTP status code" This reverts commit b0629f6b909c7d953267542ed84718d1ee63862c. --- osc/connection.py | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/osc/connection.py b/osc/connection.py index 856804eb..a0858139 100644 --- a/osc/connection.py +++ b/osc/connection.py @@ -141,12 +141,12 @@ def http_request_wrap_file(func): Turn file path into a file object and close it automatically by using a context manager. """ - def new_func(method, url, headers=None, data=None, file=None, retry_on_400: bool = True): + def new_func(method, url, headers=None, data=None, file=None): if file: with open(file, "rb") as f: - return func(method, url, headers, data, f, retry_on_400) + return func(method, url, headers, data, file=f) else: - return func(method, url, headers, data, file, retry_on_400) + return func(method, url, headers, data, file) new_func.__name__ = func.__name__ new_func.__doc__ = func.__doc__ @@ -154,7 +154,7 @@ def http_request_wrap_file(func): @http_request_wrap_file -def http_request(method: str, url: str, headers=None, data=None, file=None, retry_on_400: bool = True): +def http_request(method: str, url: str, headers=None, data=None, file=None): """ Send a HTTP request to a server. @@ -174,7 +174,6 @@ def http_request(method: str, url: str, headers=None, data=None, file=None, retr :param headers: Dictionary of custom headers to send. :param data: Data to send in the request body (conflicts with `file`). :param file: Path to a file to send as data in the request body (conflicts with `data`). - :param retry_on_400: Whether to retry on receiving HTTP status code 400. """ purl = urllib3.util.parse_url(url) @@ -234,22 +233,16 @@ def http_request(method: str, url: str, headers=None, data=None, file=None, retr else: retries_kwargs = {"method_whitelist": None} - - status_forcelist = ( - 500, # Internal Server Error - 502, # Bad Gateway - 503, # Service Unavailable - 504, # Gateway Timeout - ) - if retry_on_400: - status_forcelist = ( - 400, # Bad Request; retry on 400: service in progress - ) + status_forcelist - pool_kwargs["retries"] = urllib3.Retry( total=int(conf.config["http_retries"]), backoff_factor=2, - status_forcelist=status_forcelist, + status_forcelist=( + 400, # Bad Request; retry on 400: service in progress + 500, # Internal Server Error + 502, # Bad Gateway + 503, # Service Unavailable + 504, # Gateway Timeout + ), # don't raise because we want an actual response rather than a MaxRetryError with "too many error responses" message raise_on_status=False, **retries_kwargs,