@@ -74,10 +74,11 @@ def __call_api(
7474 _preload_content = _preload_content , _request_timeout = _request_timeout
7575 )
7676 except AuthorizationException as ae :
77- if ae .token_expired :
78- logger .error (
79- f'authentication token has expired, refreshing the token. request= { method } { resource_path } ' )
80- # if the token has expired, lets refresh the token
77+ if ae .token_expired or ae .invalid_token :
78+ token_status = "expired" if ae .token_expired else "invalid"
79+ logger .warning (
80+ f'authentication token is { token_status } , refreshing the token. request= { method } { resource_path } ' )
81+ # if the token has expired or is invalid, lets refresh the token
8182 self .__force_refresh_auth_token ()
8283 # and now retry the same request
8384 return self .__call_api_no_retry (
@@ -87,7 +88,7 @@ def __call_api(
8788 _return_http_data_only = _return_http_data_only , collection_formats = collection_formats ,
8889 _preload_content = _preload_content , _request_timeout = _request_timeout
8990 )
90- raise ae
91+ raise ae
9192
9293 def __call_api_no_retry (
9394 self , resource_path , method , path_params = None ,
@@ -266,7 +267,7 @@ def __deserialize(self, data, klass):
266267 if data is None :
267268 return None
268269
269- if type (klass ) == str :
270+ if isinstance (klass , str ) :
270271 if klass .startswith ('list[' ):
271272 sub_kls = re .match (r'list\[(.*)\]' , klass ).group (1 )
272273 return [self .__deserialize (sub_data , sub_kls )
@@ -290,7 +291,7 @@ def __deserialize(self, data, klass):
290291
291292 if klass in self .PRIMITIVE_TYPES :
292293 return self .__deserialize_primitive (data , klass )
293- elif klass == object :
294+ elif klass is object :
294295 return self .__deserialize_object (data )
295296 elif klass == datetime .date :
296297 return self .__deserialize_date (data )
@@ -567,7 +568,7 @@ def __deserialize_primitive(self, data, klass):
567568 :return: int, long, float, str, bool.
568569 """
569570 try :
570- if klass == str and type (data ) == bytes :
571+ if klass is str and isinstance (data , bytes ) :
571572 return self .__deserialize_bytes_to_str (data )
572573 return klass (data )
573574 except UnicodeEncodeError :
@@ -669,7 +670,7 @@ def __get_authentication_headers(self):
669670
670671 if time_since_last_update > self .configuration .auth_token_ttl_msec :
671672 # time to refresh the token
672- logger .debug (f 'refreshing authentication token' )
673+ logger .debug ('refreshing authentication token' )
673674 token = self .__get_new_token ()
674675 self .configuration .update_token (token )
675676
@@ -699,9 +700,10 @@ def __force_refresh_auth_token(self) -> None:
699700 def __get_new_token (self ) -> str :
700701 try :
701702 if self .configuration .authentication_settings .key_id is None or self .configuration .authentication_settings .key_secret is None :
702- logger .error ('Authentication Key or Secret is set. Failed to get the auth token' )
703+ logger .error ('Authentication Key or Secret is not set. Failed to get the auth token' )
703704 return None
704705
706+ logger .debug ('Requesting new authentication token from server' )
705707 response = self .call_api (
706708 '/token' , 'POST' ,
707709 header_params = {
0 commit comments