From d5c23edff9f9bbccabb3a6693e24916d743cc6ff Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ma=C3=ABl=20Kervella?= Date: Fri, 25 May 2018 14:00:06 +0000 Subject: [PATCH] Remove buggy save token to file in __del__ --- re2oapi/client.py | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/re2oapi/client.py b/re2oapi/client.py index 3004750..31ecb7e 100644 --- a/re2oapi/client.py +++ b/re2oapi/client.py @@ -45,13 +45,8 @@ class Re2oAPIClient: self.token = self._get_token_from_file() except Exception: self.token = self._get_token_from_server() - - def __del__(self): - try: self._save_token_to_file() - except Exception: - pass - + @property def need_renew_token(self): """ @@ -96,9 +91,12 @@ class Re2oAPIClient: 'expiration': self.token['expiration'].isoformat() } - with self.token_file.open('w') as f: - json.dump(data, f) - self.token_file.chmod(stat.S_IWRITE | stat.S_IREAD) + try: + with self.token_file.open('w') as f: + json.dump(data, f) + self.token_file.chmod(stat.S_IWRITE | stat.S_IREAD) + except Exception: + pass def _get_token_from_server(self): response = requests.post( @@ -120,6 +118,7 @@ class Re2oAPIClient: """ if self.need_renew_token: self.token = self._get_token_from_server() + self._save_token_to_file() return self.token['token'] def get(self, url, headers={}, params={}, *args, **kwargs):