88 This package is licensed under the MIT License.
99
1010--------------------------------------------------------------------------------
11- This module manages API requests with Mist Cloud. It is used to
11+ This module manages API requests with Mist Cloud. It is used to
1212* generate the URL based on the provided parameters
1313* add the required HTTP Headers to the request
1414* report error if any
@@ -64,13 +64,16 @@ def _url(self, uri) -> str:
6464 """
6565 logger .debug ("apirequest:_url:https://%s%s" , self ._cloud_uri , uri )
6666 return f"https://{ self ._cloud_uri } { uri } "
67-
67+
6868 def _log_proxy (self ) -> None :
69- pwd_regex = r' :([^:@]*)@'
69+ pwd_regex = r" :([^:@]*)@"
7070 if self ._session .proxies .get ("https" ):
71- logger .info (f"apirequest:sending request to proxy server { re .sub (pwd_regex , ':*********@' , self ._session .proxies ['https' ])} " )
72- print (f"apirequest:sending request to proxy server { re .sub (pwd_regex , ':*********@' , self ._session .proxies ['https' ])} " )
73-
71+ logger .info (
72+ f"apirequest:sending request to proxy server { re .sub (pwd_regex , ':*********@' , self ._session .proxies ['https' ])} "
73+ )
74+ print (
75+ f"apirequest:sending request to proxy server { re .sub (pwd_regex , ':*********@' , self ._session .proxies ['https' ])} "
76+ )
7477
7578 def _next_apitoken (self ) -> None :
7679 logger .info ("apirequest:_next_apitoken:rotating API Token" )
@@ -190,7 +193,9 @@ def mist_get(self, uri: str, query: dict = None) -> APIResponse:
190193 return self .mist_get (uri , query )
191194 logger .error (f"apirequest:mist_get:HTTP error occurred: { http_err } " )
192195 if resp :
193- logger .error (f"apirequest:mist_get:HTTP error description: { resp .json ()} " )
196+ logger .error (
197+ f"apirequest:mist_get:HTTP error description: { resp .json ()} "
198+ )
194199 except Exception as err :
195200 logger .error (f"apirequest:mist_get:Other error occurred: { err } " )
196201 logger .error ("apirequest:mist_get:Exception occurred" , exc_info = True )
@@ -232,7 +237,7 @@ def mist_post(self, uri: str, body: dict = None) -> APIResponse:
232237 logger .debug (f"apirequest:mist_post:request body:{ resp .request .body } " )
233238 resp .raise_for_status ()
234239 except requests .exceptions .ProxyError as proxy_error :
235- logger .error (f"apirequest:mist_post:Proxy Error: { proxy_error } " )
240+ logger .error (f"apirequest:mist_post:Proxy Error: { proxy_error } " )
236241 proxy_failed = True
237242 except requests .exceptions .ConnectionError as connexion_error :
238243 logger .error (f"Capirequest:mist_post:Connection Error: { connexion_error } " )
@@ -246,7 +251,9 @@ def mist_post(self, uri: str, body: dict = None) -> APIResponse:
246251 return self .mist_post (uri , body )
247252 logger .error (f"apirequest:mist_post: HTTP error occurred: { http_err } " )
248253 if resp :
249- logger .error (f"apirequest:mist_post: HTTP error description: { resp .json ()} " )
254+ logger .error (
255+ f"apirequest:mist_post: HTTP error description: { resp .json ()} "
256+ )
250257 except Exception as err :
251258 logger .error (f"apirequest:mist_post: Other error occurred: { err } " )
252259 logger .error ("apirequest:mist_post: Exception occurred" , exc_info = True )
@@ -288,7 +295,7 @@ def mist_put(self, uri: str, body: dict = None) -> APIResponse:
288295 logger .debug (f"apirequest:mist_put:request body:{ resp .request .body } " )
289296 resp .raise_for_status ()
290297 except requests .exceptions .ProxyError as proxy_error :
291- logger .error (f"apirequest:mist_put:Proxy Error: { proxy_error } " )
298+ logger .error (f"apirequest:mist_put:Proxy Error: { proxy_error } " )
292299 proxy_failed = True
293300 except requests .exceptions .ConnectionError as connexion_error :
294301 logger .error (f"apirequest:mist_put:Connection Error: { connexion_error } " )
@@ -302,7 +309,9 @@ def mist_put(self, uri: str, body: dict = None) -> APIResponse:
302309 return self .mist_put (uri , body )
303310 logger .error (f"apirequest:mist_put: HTTP error occurred: { http_err } " )
304311 if resp :
305- logger .error (f"apirequest:mist_put: HTTP error description: { resp .json ()} " )
312+ logger .error (
313+ f"apirequest:mist_put: HTTP error description: { resp .json ()} "
314+ )
306315 except Exception as err :
307316 logger .error (f"apirequest:mist_put: Other error occurred: { err } " )
308317 logger .error ("apirequest:mist_put: Exception occurred" , exc_info = True )
@@ -336,7 +345,7 @@ def mist_delete(self, uri: str, query: dict = None) -> APIResponse:
336345 )
337346 resp .raise_for_status ()
338347 except requests .exceptions .ProxyError as proxy_error :
339- logger .error (f"apirequest:mist_delete:Proxy Error: { proxy_error } " )
348+ logger .error (f"apirequest:mist_delete:Proxy Error: { proxy_error } " )
340349 proxy_failed = True
341350 except requests .exceptions .ConnectionError as connexion_error :
342351 logger .error (f"apirequest:mist_delete:Connection Error: { connexion_error } " )
@@ -403,7 +412,7 @@ def mist_post_file(self, uri: str, multipart_form_data: dict = {}) -> APIRespons
403412 None ,
404413 json .dumps (multipart_form_data [key ]),
405414 )
406- except :
415+ except ( OSError , json . JSONDecodeError ) :
407416 logger .error (
408417 f"apirequest:mist_post_file:multipart_form_data:"
409418 f"Unable to parse JSON object { key } "
@@ -427,10 +436,12 @@ def mist_post_file(self, uri: str, multipart_form_data: dict = {}) -> APIRespons
427436 )
428437 resp .raise_for_status ()
429438 except requests .exceptions .ProxyError as proxy_error :
430- logger .error (f"apirequest:mist_post_file:Proxy Error: { proxy_error } " )
439+ logger .error (f"apirequest:mist_post_file:Proxy Error: { proxy_error } " )
431440 proxy_failed = True
432441 except requests .exceptions .ConnectionError as connexion_error :
433- logger .error (f"apirequest:mist_post_file:Connection Error: { connexion_error } " )
442+ logger .error (
443+ f"apirequest:mist_post_file:Connection Error: { connexion_error } "
444+ )
434445 except HTTPError as http_err :
435446 if http_err .response .status_code == 429 :
436447 logger .warning (
@@ -441,7 +452,9 @@ def mist_post_file(self, uri: str, multipart_form_data: dict = {}) -> APIRespons
441452 return self .mist_post_file (uri , multipart_form_data )
442453 logger .error (f"apirequest:mist_post_file: HTTP error occurred: { http_err } " )
443454 if resp :
444- logger .error (f"apirequest:mist_post_file: HTTP error description: { resp .json ()} " )
455+ logger .error (
456+ f"apirequest:mist_post_file: HTTP error description: { resp .json ()} "
457+ )
445458 except Exception as err :
446459 logger .error (f"apirequest:mist_post_file: Other error occurred: { err } " )
447460 logger .error ("apirequest:mist_post_file: Exception occurred" , exc_info = True )
0 commit comments