Better handle of redirections.
This commit is contained in:
parent
b12df74fe7
commit
1f8366055d
1 changed files with 11 additions and 2 deletions
|
@ -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):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue