diff --git a/src/conductor/client/http/api_client.py b/src/conductor/client/http/api_client.py index 1622e8054..5b6413752 100644 --- a/src/conductor/client/http/api_client.py +++ b/src/conductor/client/http/api_client.py @@ -74,10 +74,11 @@ def __call_api( _preload_content=_preload_content, _request_timeout=_request_timeout ) except AuthorizationException as ae: - if ae.token_expired: - logger.error( - f'authentication token has expired, refreshing the token. request= {method} {resource_path}') - # if the token has expired, lets refresh the token + if ae.token_expired or ae.invalid_token: + token_status = "expired" if ae.token_expired else "invalid" + logger.warning( + f'authentication token is {token_status}, refreshing the token. request= {method} {resource_path}') + # if the token has expired or is invalid, lets refresh the token self.__force_refresh_auth_token() # and now retry the same request return self.__call_api_no_retry( @@ -87,7 +88,7 @@ def __call_api( _return_http_data_only=_return_http_data_only, collection_formats=collection_formats, _preload_content=_preload_content, _request_timeout=_request_timeout ) - raise ae + raise ae def __call_api_no_retry( self, resource_path, method, path_params=None, @@ -266,7 +267,7 @@ def __deserialize(self, data, klass): if data is None: return None - if type(klass) == str: + if isinstance(klass, str): if klass.startswith('list['): sub_kls = re.match(r'list\[(.*)\]', klass).group(1) return [self.__deserialize(sub_data, sub_kls) @@ -290,7 +291,7 @@ def __deserialize(self, data, klass): if klass in self.PRIMITIVE_TYPES: return self.__deserialize_primitive(data, klass) - elif klass == object: + elif klass is object: return self.__deserialize_object(data) elif klass == datetime.date: return self.__deserialize_date(data) @@ -567,7 +568,7 @@ def __deserialize_primitive(self, data, klass): :return: int, long, float, str, bool. """ try: - if klass == str and type(data) == bytes: + if klass is str and isinstance(data, bytes): return self.__deserialize_bytes_to_str(data) return klass(data) except UnicodeEncodeError: @@ -669,7 +670,7 @@ def __get_authentication_headers(self): if time_since_last_update > self.configuration.auth_token_ttl_msec: # time to refresh the token - logger.debug(f'refreshing authentication token') + logger.debug('refreshing authentication token') token = self.__get_new_token() self.configuration.update_token(token) @@ -699,9 +700,10 @@ def __force_refresh_auth_token(self) -> None: def __get_new_token(self) -> str: try: if self.configuration.authentication_settings.key_id is None or self.configuration.authentication_settings.key_secret is None: - logger.error('Authentication Key or Secret is set. Failed to get the auth token') + logger.error('Authentication Key or Secret is not set. Failed to get the auth token') return None + logger.debug('Requesting new authentication token from server') response = self.call_api( '/token', 'POST', header_params={