@@ -36,7 +36,7 @@ def _req_post(
3636 json = data ,
3737 files = files ,
3838 verify = self .verify ,
39- timeout = 120 ,
39+ timeout = self . timeout ,
4040 headers = self .headers ,
4141 )
4242
@@ -55,7 +55,7 @@ def _req_get(
5555 return self .session .get (
5656 self .url_prefix + url + apiSrcStr ,
5757 verify = self .verify ,
58- timeout = 120 ,
58+ timeout = self . timeout ,
5959 headers = self .headers ,
6060 )
6161
@@ -74,7 +74,7 @@ def _req_delete(
7474 return self .session .delete (
7575 self .url_prefix + url + apiSrcStr ,
7676 verify = self .verify ,
77- timeout = 120 ,
77+ timeout = self . timeout ,
7878 headers = self .headers ,
7979 )
8080
@@ -97,7 +97,7 @@ def _req_put(
9797 self .url_prefix + url + apiSrcStr ,
9898 json = data ,
9999 verify = self .verify ,
100- timeout = 120 ,
100+ timeout = self . timeout ,
101101 headers = self .headers ,
102102 )
103103
@@ -221,6 +221,11 @@ def _post(
221221 api_path , response , expected_status , return_type
222222 )
223223
224+ except requests .exceptions .ConnectTimeout :
225+ self .logger .error (
226+ f"POST { api_path } | Request Timed Out - "
227+ f"Timeout values (connect/read): { self .timeout } "
228+ )
224229 except Exception as ex :
225230 self .logger .error (
226231 "Exception {} when calling POST {}. Traceback: {}" .format (
@@ -263,7 +268,11 @@ def _get(
263268 return self ._handle_response (
264269 api_path , response , expected_status , return_type
265270 )
266-
271+ except requests .exceptions .ConnectTimeout :
272+ self .logger .error (
273+ f"GET { api_path } | Request Timed Out - "
274+ f"Timeout values (connect/read): { self .timeout } "
275+ )
267276 except Exception as ex :
268277 self .logger .error (
269278 "Exception {} when calling GET {}. Traceback: {}" .format (
@@ -306,7 +315,11 @@ def _delete(
306315 return self ._handle_response (
307316 api_path , response , expected_status , return_type
308317 )
309-
318+ except requests .exceptions .ConnectTimeout :
319+ self .logger .error (
320+ f"DELETE { api_path } | Request Timed Out - "
321+ f"Timeout values (connect/read): { self .timeout } "
322+ )
310323 except Exception as ex :
311324 self .logger .error (
312325 "Exception {} when calling DELETE {}. Traceback: {}" .format (
@@ -352,7 +365,11 @@ def _put(
352365 return self ._handle_response (
353366 api_path , response , expected_status , return_type
354367 )
355-
368+ except requests .exceptions .ConnectTimeout :
369+ self .logger .error (
370+ f"PUT { api_path } | Request Timed Out - "
371+ f"Timeout values (connect/read): { self .timeout } "
372+ )
356373 except Exception as ex :
357374 self .logger .error (
358375 "Exception {} when calling PUT {}. Traceback: {}" .format (
@@ -377,6 +394,7 @@ def __init__(
377394 log_console : bool = False ,
378395 log_success : bool = False ,
379396 verify_ssl : bool = True ,
397+ timeout : tuple = (9.15 , 12 ),
380398 ):
381399 """Setup Orchestrator instance
382400
@@ -409,6 +427,11 @@ def __init__(
409427 :param verify_ssl: Set to ``False`` to ignore certificate
410428 warnings within requests, defaults to ``True``
411429 :type verify_ssl: bool, optional
430+ :param timeout: Timeout values (in seconds) for requests, first
431+ value is for initial connection, second value is for read
432+ timeouts. Defaults to ``(9.15, 12)``, 9.15 seconds for
433+ connection, 12 seconds for server data response.
434+ :type timeout: tuple, optional
412435 :raises ValueError: If Orchestrator auth_mode specified not in
413436 supported_auth_modes
414437 """
@@ -420,6 +443,7 @@ def __init__(
420443 )
421444
422445 self .url_prefix = "https://" + url + "/gms/rest"
446+ self .timeout = timeout
423447 self .session = requests .Session ()
424448 if api_key != "" :
425449 self .headers = {"X-Auth-Token" : api_key }
@@ -1233,6 +1257,7 @@ def __init__(
12331257 log_console : bool = False ,
12341258 log_success : bool = False ,
12351259 verify_ssl : bool = True ,
1260+ timeout : tuple = (9.15 , 12 ),
12361261 ):
12371262 """Setup Edge Connect instance
12381263
@@ -1264,9 +1289,15 @@ def __init__(
12641289 :type log_success: bool, optional
12651290 :param verify_ssl: Set to ``False`` to ignore certificate
12661291 warnings within requests, defaults to ``True``
1292+ :param timeout: Timeout values (in seconds) for requests, first
1293+ value is for initial connection, second value is for read
1294+ timeouts. Defaults to ``(9.15, 12)``, 9.15 seconds for
1295+ connection, 12 seconds for server data response.
1296+ :type timeout: tuple, optional
12671297 :type verify_ssl: bool, optional
12681298 """
12691299 self .url_prefix = "https://" + url + ":443/rest/json"
1300+ self .timeout = timeout
12701301 self .session = requests .Session ()
12711302 self .headers = {}
12721303 # for API calls w/ just source as query param
0 commit comments