diff --git a/re2oapi/client.py b/re2oapi/client.py index 2fb15d2..7a8f3d1 100644 --- a/re2oapi/client.py +++ b/re2oapi/client.py @@ -235,10 +235,19 @@ class Re2oAPIClient: # Perform the request self.log.info("Performing request {} {}".format(method.upper(), url)) response = getattr(requests, method)( - url, headers=headers, params=params, *args, **kwargs + url, headers=headers, params=params, + allow_redirects=False, *args, **kwargs ) self.log.debug("Response code: "+str(response.status_code)) + if response.is_redirect: + self.log.debug("Redirection detected.") + response = getattr(requests, method)( + response.headers['Location'], headers=headers, params=params, + allow_redirects=False, *args, **kwargs + ) + self.log.debug("Response code after redirection: "+str(response.status_code)) + if response.status_code == requests.codes.unauthorized: # Force re-login to the server (case of a wrong token but valid # credentials) and then retry the request without catching errors. @@ -262,7 +271,7 @@ class Re2oAPIClient: response.raise_for_status() ret = response.json() - self.log.debug("Request {} {} successful.".format(method, url)) + self.log.debug("Request {} {} successful.".format(method, response.url)) return ret def delete(self, *args, **kwargs):