@@ -41,7 +41,8 @@ class APIClientArgs:
4141 # single_conn is set to True by default, when work on parallel set to False
4242 def __init__ (self , port = None , fingerprint = None , sid = None , server = "127.0.0.1" , http_debug_level = 0 ,
4343 api_calls = None , debug_file = "" , proxy_host = None , proxy_port = 8080 ,
44- api_version = None , unsafe = False , unsafe_auto_accept = False , context = "web_api" , single_conn = True , user_agent = "python-api-wrapper" ):
44+ api_version = None , unsafe = False , unsafe_auto_accept = False , context = "web_api" , single_conn = True ,
45+ user_agent = "python-api-wrapper" ):
4546 self .port = port
4647 # management server fingerprint
4748 self .fingerprint = fingerprint
@@ -120,7 +121,6 @@ def __init__(self, api_client_args=None):
120121 # User agent will be use in api call request header
121122 self .user_agent = api_client_args .user_agent
122123
123-
124124 def __enter__ (self ):
125125 return self
126126
@@ -324,7 +324,7 @@ def api_call(self, command, payload=None, sid=None, wait_for_task=True, timeout=
324324 res = APIResponse ("" , False , err_message = err_message )
325325 else :
326326 res = APIResponse ("" , False , err_message = err )
327- except (http_client .CannotSendRequest , http_client .BadStatusLine ) as e :
327+ except (http_client .CannotSendRequest , http_client .BadStatusLine , ConnectionAbortedError ) as e :
328328 self .conn = self .create_https_connection ()
329329 self .conn .request ("POST" , url , _data , _headers )
330330 response = self .conn .getresponse ()
@@ -345,16 +345,17 @@ def api_call(self, command, payload=None, sid=None, wait_for_task=True, timeout=
345345 json_data ["password" ] = "****"
346346 _data = json .dumps (json_data )
347347
348- # Store the request and the reply (for debug purpose).
349- _api_log = {
350- "request" : {
351- "url" : url ,
352- "payload" : compatible_loads (_data ),
353- "headers" : _headers
354- },
355- "response" : res .response ()
356- }
357- self .api_calls .append (_api_log )
348+ if self .debug_file :
349+ # Store the request and the reply (for debug purpose).
350+ _api_log = {
351+ "request" : {
352+ "url" : url ,
353+ "payload" : compatible_loads (_data ),
354+ "headers" : _headers
355+ },
356+ "response" : res .response ()
357+ }
358+ self .api_calls .append (_api_log )
358359
359360 # If we want to wait for the task to end, wait for it
360361 if wait_for_task is True and res .success and command != "show-task" :
0 commit comments