From 50ee8d9a66b6a9544d42a7cdde93ca88eb1520a2 Mon Sep 17 00:00:00 2001 From: Christophe Vandeplas Date: Thu, 21 May 2020 20:31:19 +0200 Subject: [PATCH 1/8] new: Timeout for connection/request, fixes #584 --- pymisp/api.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/pymisp/api.py b/pymisp/api.py index c581cc51d..10b795bc0 100644 --- a/pymisp/api.py +++ b/pymisp/api.py @@ -88,10 +88,11 @@ class PyMISP: :param cert: Client certificate, as described there: http://docs.python-requests.org/en/master/user/advanced/#client-side-certificates :param auth: The auth parameter is passed directly to requests, as described here: http://docs.python-requests.org/en/master/user/authentication/ :param tool: The software using PyMISP (string), used to set a unique user-agent + :param timeout: Timeout as described here: https://requests.readthedocs.io/en/master/user/advanced/#timeouts """ def __init__(self, url: str, key: str, ssl: bool=True, debug: bool=False, proxies: Mapping={}, - cert: Tuple[str, tuple]=None, auth: AuthBase=None, tool: str=''): + cert: Tuple[str, tuple]=None, auth: AuthBase=None, tool: str='', timeout: Union[float, tuple]=None): if not url: raise NoURL('Please provide the URL of your MISP instance.') if not key: @@ -104,6 +105,7 @@ def __init__(self, url: str, key: str, ssl: bool=True, debug: bool=False, proxie self.cert: Optional[Tuple[str, tuple]] = cert self.auth: Optional[AuthBase] = auth self.tool: str = tool + self.timeout: float = timeout self.global_pythonify = False @@ -2353,7 +2355,7 @@ def _prepare_request(self, request_type: str, url: str, data: Union[str, Iterato if logger.isEnabledFor(logging.DEBUG): logger.debug(prepped.headers) settings = s.merge_environment_settings(req.url, proxies=self.proxies or {}, stream=None, verify=self.ssl, cert=self.cert) - return s.send(prepped, **settings) + return s.send(prepped, timeout=self.timeout, **settings) def _csv_to_dict(self, csv_content: str) -> List[dict]: '''Makes a list of dict out of a csv file (requires headers)''' From d745d5b22642fc239de93c3e3106147aa1accaeb Mon Sep 17 00:00:00 2001 From: Christophe Vandeplas Date: Thu, 21 May 2020 20:44:42 +0200 Subject: [PATCH 2/8] fix: fixes bug in timeout change --- pymisp/api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pymisp/api.py b/pymisp/api.py index 10b795bc0..fac015366 100644 --- a/pymisp/api.py +++ b/pymisp/api.py @@ -92,7 +92,7 @@ class PyMISP: """ def __init__(self, url: str, key: str, ssl: bool=True, debug: bool=False, proxies: Mapping={}, - cert: Tuple[str, tuple]=None, auth: AuthBase=None, tool: str='', timeout: Union[float, tuple]=None): + cert: Tuple[str, tuple]=None, auth: AuthBase=None, tool: str='', timeout: Union[float, Tuple[float, float]]=None): if not url: raise NoURL('Please provide the URL of your MISP instance.') if not key: From d09852fa4b4821c5491ed224e1b6701cfc4dd207 Mon Sep 17 00:00:00 2001 From: Christophe Vandeplas Date: Thu, 21 May 2020 20:59:28 +0200 Subject: [PATCH 3/8] fix: fixes bug in timeout change --- pymisp/api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pymisp/api.py b/pymisp/api.py index fac015366..4ad768117 100644 --- a/pymisp/api.py +++ b/pymisp/api.py @@ -92,7 +92,7 @@ class PyMISP: """ def __init__(self, url: str, key: str, ssl: bool=True, debug: bool=False, proxies: Mapping={}, - cert: Tuple[str, tuple]=None, auth: AuthBase=None, tool: str='', timeout: Union[float, Tuple[float, float]]=None): + cert: Tuple[str, tuple]=None, auth: AuthBase=None, tool: str='', timeout: Union[float, Tuple[float, float], None]=None): if not url: raise NoURL('Please provide the URL of your MISP instance.') if not key: From e74a0a42690a8a5cd733ac4cbd6849f0d72be192 Mon Sep 17 00:00:00 2001 From: Christophe Vandeplas Date: Thu, 21 May 2020 21:30:28 +0200 Subject: [PATCH 4/8] fix: fixes bug in timeout change hail to Rafiot --- pymisp/api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pymisp/api.py b/pymisp/api.py index 4ad768117..78bedcf7c 100644 --- a/pymisp/api.py +++ b/pymisp/api.py @@ -105,7 +105,7 @@ def __init__(self, url: str, key: str, ssl: bool=True, debug: bool=False, proxie self.cert: Optional[Tuple[str, tuple]] = cert self.auth: Optional[AuthBase] = auth self.tool: str = tool - self.timeout: float = timeout + self.timeout: Optional[float, Tuple[float, float]] = timeout self.global_pythonify = False From fa639d8aa9da0b431511733327033a552abf6185 Mon Sep 17 00:00:00 2001 From: Christophe Vandeplas Date: Thu, 21 May 2020 21:46:24 +0200 Subject: [PATCH 5/8] fix: fixes bug in timeout change --- pymisp/api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pymisp/api.py b/pymisp/api.py index 78bedcf7c..d0a7d1c6c 100644 --- a/pymisp/api.py +++ b/pymisp/api.py @@ -105,7 +105,7 @@ def __init__(self, url: str, key: str, ssl: bool=True, debug: bool=False, proxie self.cert: Optional[Tuple[str, tuple]] = cert self.auth: Optional[AuthBase] = auth self.tool: str = tool - self.timeout: Optional[float, Tuple[float, float]] = timeout + self.timeout: Optional[float, Tuple[float, float], None] = timeout self.global_pythonify = False From 12f8fd85300e5ce71ee1d9e3287bafb600e2a4af Mon Sep 17 00:00:00 2001 From: Christophe Vandeplas Date: Thu, 21 May 2020 21:49:25 +0200 Subject: [PATCH 6/8] fix: fixes bug in timeout change --- pymisp/api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pymisp/api.py b/pymisp/api.py index d0a7d1c6c..b18663430 100644 --- a/pymisp/api.py +++ b/pymisp/api.py @@ -105,7 +105,7 @@ def __init__(self, url: str, key: str, ssl: bool=True, debug: bool=False, proxie self.cert: Optional[Tuple[str, tuple]] = cert self.auth: Optional[AuthBase] = auth self.tool: str = tool - self.timeout: Optional[float, Tuple[float, float], None] = timeout + self.timeout: Optional[Union[float, Tuple[float, float], None]] = timeout self.global_pythonify = False From f3b3f4c13c6912d1e3050867875d0bca08d225ec Mon Sep 17 00:00:00 2001 From: Christophe Vandeplas Date: Thu, 21 May 2020 21:52:42 +0200 Subject: [PATCH 7/8] fix: fixes bug in timeout change --- pymisp/api.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pymisp/api.py b/pymisp/api.py index b18663430..e1b7896d9 100644 --- a/pymisp/api.py +++ b/pymisp/api.py @@ -92,7 +92,7 @@ class PyMISP: """ def __init__(self, url: str, key: str, ssl: bool=True, debug: bool=False, proxies: Mapping={}, - cert: Tuple[str, tuple]=None, auth: AuthBase=None, tool: str='', timeout: Union[float, Tuple[float, float], None]=None): + cert: Tuple[str, tuple]=None, auth: AuthBase=None, tool: str='', timeout: Optional[float, Tuple[float, float]]=None): if not url: raise NoURL('Please provide the URL of your MISP instance.') if not key: @@ -105,7 +105,7 @@ def __init__(self, url: str, key: str, ssl: bool=True, debug: bool=False, proxie self.cert: Optional[Tuple[str, tuple]] = cert self.auth: Optional[AuthBase] = auth self.tool: str = tool - self.timeout: Optional[Union[float, Tuple[float, float], None]] = timeout + self.timeout: Optional[float, Tuple[float, float]]] = timeout self.global_pythonify = False From 515a47a59181e53293fd625501ee6987b5d20e70 Mon Sep 17 00:00:00 2001 From: Christophe Vandeplas Date: Thu, 21 May 2020 22:01:26 +0200 Subject: [PATCH 8/8] fix: fixes bug in timeout change --- pymisp/api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pymisp/api.py b/pymisp/api.py index e1b7896d9..a77dd5618 100644 --- a/pymisp/api.py +++ b/pymisp/api.py @@ -105,7 +105,7 @@ def __init__(self, url: str, key: str, ssl: bool=True, debug: bool=False, proxie self.cert: Optional[Tuple[str, tuple]] = cert self.auth: Optional[AuthBase] = auth self.tool: str = tool - self.timeout: Optional[float, Tuple[float, float]]] = timeout + self.timeout: Optional[float, Tuple[float, float]] = timeout self.global_pythonify = False