Commit 1d5dbff3a053a78fee730c5c58eaf02ae32ab76a
1 parent
f56fa9dd
Exists in
dev
Add deletion of token if token is invalid
Showing
1 changed file
with
8 additions
and
0 deletions
Show diff stats
pyros_api.py
... | ... | @@ -107,6 +107,9 @@ class PyrosAPI: |
107 | 107 | f"Server {self.host} doesn't respond. The website might be down.") |
108 | 108 | exit(1) |
109 | 109 | print(f"Request status code {request.status_code}") |
110 | + if request.status_code == 401: | |
111 | + print("Bad token, disconnecting from webserver. Please authenticate yourself next time.") | |
112 | + self.delete_token() | |
110 | 113 | return request.json() |
111 | 114 | |
112 | 115 | def get_sequences_for_period(self, start_date: str, end_date: str) -> dict: |
... | ... | @@ -140,6 +143,11 @@ class PyrosAPI: |
140 | 143 | exit(1) |
141 | 144 | return response.content.decode("utf-8") |
142 | 145 | |
146 | + def delete_token(self): | |
147 | + if os.path.exists("TOKEN"): | |
148 | + os.remove("TOKEN") | |
149 | + print("Token deleted") | |
150 | + | |
143 | 151 | |
144 | 152 | @click.group() |
145 | 153 | @click.option('--host', '-h', help='host name (example: http://localhost:8000 or http://pyros.omp.eu) without last slash') | ... | ... |