@@ -75,7 +75,7 @@ def __call_api(
7575 )
7676 except AuthorizationException as ae :
7777 if ae .token_expired :
78- logger .error (
78+ logger .warning (
7979 f'authentication token has expired, refreshing the token. request= { method } { resource_path } ' )
8080 # if the token has expired, lets refresh the token
8181 self .__force_refresh_auth_token ()
@@ -87,6 +87,19 @@ def __call_api(
8787 _return_http_data_only = _return_http_data_only , collection_formats = collection_formats ,
8888 _preload_content = _preload_content , _request_timeout = _request_timeout
8989 )
90+ elif ae .invalid_token :
91+ logger .warning (
92+ f'authentication token is invalid, refreshing the token. request= { method } { resource_path } ' )
93+ # if the token is invalid, lets refresh the token
94+ self .__force_refresh_auth_token ()
95+ # and now retry the same request
96+ return self .__call_api_no_retry (
97+ resource_path = resource_path , method = method , path_params = path_params ,
98+ query_params = query_params , header_params = header_params , body = body , post_params = post_params ,
99+ files = files , response_type = response_type , auth_settings = auth_settings ,
100+ _return_http_data_only = _return_http_data_only , collection_formats = collection_formats ,
101+ _preload_content = _preload_content , _request_timeout = _request_timeout
102+ )
90103 raise ae
91104
92105 def __call_api_no_retry (
@@ -266,7 +279,7 @@ def __deserialize(self, data, klass):
266279 if data is None :
267280 return None
268281
269- if type (klass ) == str :
282+ if isinstance (klass , str ) :
270283 if klass .startswith ('list[' ):
271284 sub_kls = re .match (r'list\[(.*)\]' , klass ).group (1 )
272285 return [self .__deserialize (sub_data , sub_kls )
@@ -290,7 +303,7 @@ def __deserialize(self, data, klass):
290303
291304 if klass in self .PRIMITIVE_TYPES :
292305 return self .__deserialize_primitive (data , klass )
293- elif klass == object :
306+ elif klass is object :
294307 return self .__deserialize_object (data )
295308 elif klass == datetime .date :
296309 return self .__deserialize_date (data )
@@ -567,7 +580,7 @@ def __deserialize_primitive(self, data, klass):
567580 :return: int, long, float, str, bool.
568581 """
569582 try :
570- if klass == str and type (data ) == bytes :
583+ if klass is str and isinstance (data , bytes ) :
571584 return self .__deserialize_bytes_to_str (data )
572585 return klass (data )
573586 except UnicodeEncodeError :
@@ -669,7 +682,7 @@ def __get_authentication_headers(self):
669682
670683 if time_since_last_update > self .configuration .auth_token_ttl_msec :
671684 # time to refresh the token
672- logger .debug (f 'refreshing authentication token' )
685+ logger .debug ('refreshing authentication token' )
673686 token = self .__get_new_token ()
674687 self .configuration .update_token (token )
675688
@@ -699,9 +712,10 @@ def __force_refresh_auth_token(self) -> None:
699712 def __get_new_token (self ) -> str :
700713 try :
701714 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' )
715+ logger .error ('Authentication Key or Secret is not set. Failed to get the auth token' )
703716 return None
704717
718+ logger .debug ('Requesting new authentication token from server' )
705719 response = self .call_api (
706720 '/token' , 'POST' ,
707721 header_params = {
0 commit comments