From 94f8ef8aaa884cc16d93d1dff7f059316bdbf062 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niccolo=CC=80=20Zapponi?= Date: Fri, 11 Dec 2020 09:41:35 +0000 Subject: [PATCH] Fixed bug --- pyicloud/base.py | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/pyicloud/base.py b/pyicloud/base.py index 7abb914..5081b96 100644 --- a/pyicloud/base.py +++ b/pyicloud/base.py @@ -104,17 +104,21 @@ class PyiCloudSession(Session): if not response.ok and (content_type not in json_mimetypes or response.status_code in [421, 450, 500]): - if has_retried is None and response.status_code == 450 and self.service._get_webservice_url("findme") in url: - # Handle re-authentication for Find My iPhone - LOGGER.debug("Re-authenticating Find My iPhone service") - try: - self.service.authenticate(True, "find") - except PyiCloudAPIResponseException: - LOGGER.debug("Re-authentication failed") - kwargs["retried"] = True - return self.request(method, url, **kwargs) + try: + fmip_url = self.service._get_webservice_url("findme") + if has_retried is None and response.status_code == 450 and fmip_url in url: + # Handle re-authentication for Find My iPhone + LOGGER.debug("Re-authenticating Find My iPhone service") + try: + self.service.authenticate(True, "find") + except PyiCloudAPIResponseException: + LOGGER.debug("Re-authentication failed") + kwargs["retried"] = True + return self.request(method, url, **kwargs) + except Exception: + pass - elif has_retried is None and response.status_code in [421, 450, 500]: + if has_retried is None and response.status_code in [421, 450, 500]: api_error = PyiCloudAPIResponseException( response.reason, response.status_code, retry=True )