@@ -93,7 +93,6 @@ def __init__(
9393 self .signature_method = getattr (hashlib , signature_method )
9494
9595 self ._jwt_auth_params = {}
96- self .jwt = None
9796
9897 if private_key is not None and application_id is not None :
9998 self ._application_id = application_id
@@ -103,8 +102,6 @@ def __init__(
103102 with open (self ._private_key , "rb" ) as key_file :
104103 self ._private_key = key_file .read ()
105104
106- self .jwt = self ._generate_application_jwt ()
107-
108105 self ._host = "rest.nexmo.com"
109106 self ._api_host = "api.nexmo.com"
110107
@@ -115,7 +112,6 @@ def __init__(
115112
116113 self .headers = {"User-Agent" : user_agent , "Accept" : "application/json" }
117114
118-
119115 self .account = Account (self )
120116 self .application = Application (self )
121117 self .messages = Messages (self )
@@ -152,7 +148,6 @@ def api_host(self, value=None):
152148
153149 def auth (self , params = None , ** kwargs ):
154150 self ._jwt_auth_params = params or kwargs
155- self .jwt = self ._generate_application_jwt ()
156151
157152 def check_signature (self , params ):
158153 params = dict (params )
@@ -293,7 +288,7 @@ def parse(self, host, response):
293288 logger .debug (f"Response headers { repr (response .headers )} " )
294289 if response .status_code == 401 :
295290 raise AuthenticationError (
296- "Check you're using a valid authentication method for the API you want to use "
291+ "Authentication failed. Check you're using a valid authentication method. "
297292 )
298293 elif response .status_code == 204 :
299294 return None
@@ -313,7 +308,6 @@ def parse(self, host, response):
313308
314309 # Test for standard error format:
315310 try :
316-
317311 error_data = response .json ()
318312 if (
319313 "type" in error_data
@@ -334,7 +328,7 @@ def parse(self, host, response):
334328 raise ServerError (message )
335329
336330 def _add_jwt_to_request_headers (self ):
337- return dict (self .headers , Authorization = b"Bearer " + self .jwt )
331+ return dict (self .headers , Authorization = b"Bearer " + self ._generate_application_jwt () )
338332
339333 def _generate_application_jwt (self ):
340334 iat = int (time .time ())
0 commit comments