From 7fc652d1b4d1d1126190ffa4d78fa70470e1d23a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Aur=C3=A9lien=20Bompard?= Date: Mon, 30 Sep 2024 10:24:57 +0200 Subject: [PATCH] Follow redirects by default MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This is made harder by https://github.com/Yelp/bravado/issues/494 It is necessary because of https://github.com/gssapi/mod_auth_gssapi/issues/316 Signed-off-by: Aurélien Bompard --- fasjson_client/client.py | 8 +++++++- fasjson_client/response.py | 3 +++ 2 files changed, 10 insertions(+), 1 deletion(-) diff --git a/fasjson_client/client.py b/fasjson_client/client.py index 84ed14ad..96b471d4 100644 --- a/fasjson_client/client.py +++ b/fasjson_client/client.py @@ -24,6 +24,12 @@ class InvalidJSONError(RequestException): from .formats import mask_format +class RequestsClientFollowingRedirects(requests_client.RequestsClient): + def separate_params(self, request_params): + request_params["follow_redirects"] = True + return super().separate_params(request_params) + + class Client: """FASJSON client class that builds API methods based on openapi specs. @@ -66,7 +72,7 @@ def _spec_url(self): return urljoin(self._base_url, f"specs/v{self._api_version}.json") def _make_bravado_client(self): - http_client = requests_client.RequestsClient() + http_client = RequestsClientFollowingRedirects() server_hostname = urlsplit(self._base_url).netloc if self._auth: http_client.authenticator = GssapiAuthenticator( diff --git a/fasjson_client/response.py b/fasjson_client/response.py index c7f0c282..33c64a05 100644 --- a/fasjson_client/response.py +++ b/fasjson_client/response.py @@ -36,6 +36,9 @@ def __call__(self, **kwargs): Raises: APIError: if the API doesn't return a successful response """ + # Unfortunately this does not work because of + # https://github.com/Yelp/bravado/issues/494 + # kwargs.setdefault("_request_options", {})["follow_redirects"] = True try: call_result = self.operation(**kwargs).response().result except HTTPError as e: