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