Merge branch 'master' of https://gitlab.federez.net/re2o/re2oapi
This commit is contained in:
commit
ffaed92103
1 changed files with 71 additions and 61 deletions
|
@ -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):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue