diff --git a/clearml/backend_api/session/session.py b/clearml/backend_api/session/session.py index e8a1093c..c2611a32 100644 --- a/clearml/backend_api/session/session.py +++ b/clearml/backend_api/session/session.py @@ -172,7 +172,7 @@ class Session(TokenManager): # update api version from server response try: - token_dict = jwt.decode(self.token, verify=False) + token_dict = TokenManager.get_decoded_token(self.token) api_version = token_dict.get('api_version') if not api_version: api_version = '2.2' if token_dict.get('env', '') == 'prod' else Session.api_version @@ -182,7 +182,8 @@ class Session(TokenManager): Session.api_version = str(api_version) except (jwt.DecodeError, ValueError): - pass + (self._logger or get_logger()).warning( + "Failed parsing server API level, defaulting to {}".format(Session.api_version)) # now setup the session reporting, so one consecutive retries will show warning # we do that here, so if we have problems authenticating, we see them immediately diff --git a/clearml/backend_api/session/token_manager.py b/clearml/backend_api/session/token_manager.py index 0d970f90..6ee3ce36 100644 --- a/clearml/backend_api/session/token_manager.py +++ b/clearml/backend_api/session/token_manager.py @@ -68,12 +68,17 @@ class TokenManager(object): return 0 @classmethod - def _get_token_exp(cls, token): + def get_decoded_token(cls, token): """ Get token expiration time. If not present, assume forever """ return jwt.decode( token, verify=False, options=dict(verify_signature=False), - algorithms=get_default_algorithms()).get('exp', sys.maxsize) + algorithms=get_default_algorithms()) + + @classmethod + def _get_token_exp(cls, token): + """ Get token expiration time. If not present, assume forever """ + return cls.get_decoded_token(token).get('exp', sys.maxsize) def _set_token(self, token): if token: