Skip to content
Snippets Groups Projects
Commit c69d3826 authored by Jorrit Schaap's avatar Jorrit Schaap
Browse files

try/except

parent 7b77e9c4
No related branches found
No related tags found
No related merge requests found
...@@ -71,16 +71,23 @@ class TMSSWindmillStandstillEventMessageHandler(TMSSEventMessageHandler): ...@@ -71,16 +71,23 @@ class TMSSWindmillStandstillEventMessageHandler(TMSSEventMessageHandler):
self.polling_thread.join() self.polling_thread.join()
def refresh_access_token(self): def refresh_access_token(self):
try:
logger.info('refreshing access token...') logger.info('refreshing access token...')
response = requests.post(self.token_url, response = requests.post(self.token_url,
data={"grant_type": "client_credentials", data={"grant_type": "client_credentials",
"scope": self.scope, "scope": self.scope,
"client_id": self.client_id, "client_id": self.client_id,
"client_secret": self.client_secret}) "client_secret": self.client_secret})
except Exception as e:
logger.error("could not refresh access token: %s", str(e))
try:
json_response = response.json() json_response = response.json()
self.access_token = json_response["access_token"] self.access_token = json_response["access_token"]
self.access_token_expiration_date = datetime.utcnow() + timedelta(seconds=json_response['expires_in']-10) self.access_token_expiration_date = datetime.utcnow() + timedelta(seconds=json_response['expires_in']-10)
logger.info('new token valid till %s' % self.access_token_expiration_date.isoformat()) logger.info('new token valid till %s' % self.access_token_expiration_date.isoformat())
except Exception as e:
logger.error("could not refresh access token: http_status_code=%s error: %s", response.status_code, str(e))
def get_api_path_as_json(self, path): def get_api_path_as_json(self, path):
if datetime.utcnow() >= self.access_token_expiration_date: if datetime.utcnow() >= self.access_token_expiration_date:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment