Fix 450 error (#230)
- while refreshing client after 20 min of non request
This commit is contained in:
parent
623fb66b5d
commit
5368081b6b
2 changed files with 14 additions and 2 deletions
|
@ -65,12 +65,22 @@ class PyiCloudSession(requests.Session):
|
||||||
|
|
||||||
logger.debug("%s %s %s", args[0], args[1], kwargs.get('data', ''))
|
logger.debug("%s %s %s", args[0], args[1], kwargs.get('data', ''))
|
||||||
|
|
||||||
|
kwargs.pop('retried', None)
|
||||||
response = super(PyiCloudSession, self).request(*args, **kwargs)
|
response = super(PyiCloudSession, self).request(*args, **kwargs)
|
||||||
|
|
||||||
content_type = response.headers.get('Content-Type', '').split(';')[0]
|
content_type = response.headers.get('Content-Type', '').split(';')[0]
|
||||||
json_mimetypes = ['application/json', 'text/json']
|
json_mimetypes = ['application/json', 'text/json']
|
||||||
|
|
||||||
if not response.ok and content_type not in json_mimetypes:
|
if not response.ok and content_type not in json_mimetypes:
|
||||||
|
if kwargs.get('retried') is None and response.status_code == 450:
|
||||||
|
api_error = PyiCloudAPIResponseError(
|
||||||
|
response.reason,
|
||||||
|
response.status_code,
|
||||||
|
retry=True
|
||||||
|
)
|
||||||
|
logger.warn(api_error)
|
||||||
|
kwargs['retried'] = True
|
||||||
|
return self.request(*args, **kwargs)
|
||||||
self._raise_error(response.status_code, response.reason)
|
self._raise_error(response.status_code, response.reason)
|
||||||
|
|
||||||
if content_type not in json_mimetypes:
|
if content_type not in json_mimetypes:
|
||||||
|
|
|
@ -8,12 +8,14 @@ class PyiCloudNoDevicesException(PyiCloudException):
|
||||||
|
|
||||||
|
|
||||||
class PyiCloudAPIResponseError(PyiCloudException):
|
class PyiCloudAPIResponseError(PyiCloudException):
|
||||||
def __init__(self, reason, code):
|
def __init__(self, reason, code, retry=False):
|
||||||
self.reason = reason
|
self.reason = reason
|
||||||
self.code = code
|
self.code = code
|
||||||
message = reason
|
message = reason or ""
|
||||||
if code:
|
if code:
|
||||||
message += " (%s)" % code
|
message += " (%s)" % code
|
||||||
|
if retry:
|
||||||
|
message += ". Retrying ..."
|
||||||
|
|
||||||
super(PyiCloudAPIResponseError, self).__init__(message)
|
super(PyiCloudAPIResponseError, self).__init__(message)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue