This commit is contained in:
detraz 2019-10-06 16:03:33 +02:00
commit ffaed92103

View file

@ -222,6 +222,7 @@ class Re2oAPIClient:
# Update headers to force the 'Authorization' field with the right token
self.log.debug("Forcing authentication token.")
self.log.debug("Token =" + str(self.get_token()))
headers.update({
'Authorization': 'Token {}'.format(self.get_token())
})
@ -234,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.
@ -261,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):