From 1d5dbff3a053a78fee730c5c58eaf02ae32ab76a Mon Sep 17 00:00:00 2001 From: pyros_astroguita Date: Fri, 20 Oct 2023 16:53:46 +0200 Subject: [PATCH] Add deletion of token if token is invalid --- pyros_api.py | 8 ++++++++ 1 file changed, 8 insertions(+), 0 deletions(-) diff --git a/pyros_api.py b/pyros_api.py index cb2e33d..6be5229 100755 --- a/pyros_api.py +++ b/pyros_api.py @@ -107,6 +107,9 @@ class PyrosAPI: f"Server {self.host} doesn't respond. The website might be down.") exit(1) print(f"Request status code {request.status_code}") + if request.status_code == 401: + print("Bad token, disconnecting from webserver. Please authenticate yourself next time.") + self.delete_token() return request.json() def get_sequences_for_period(self, start_date: str, end_date: str) -> dict: @@ -140,6 +143,11 @@ class PyrosAPI: exit(1) return response.content.decode("utf-8") + def delete_token(self): + if os.path.exists("TOKEN"): + os.remove("TOKEN") + print("Token deleted") + @click.group() @click.option('--host', '-h', help='host name (example: http://localhost:8000 or http://pyros.omp.eu) without last slash') -- libgit2 0.21.2