Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new: Timeout for connection/request, fixes #584 #585

Merged
merged 8 commits into from
May 21, 2020
Merged
6 changes: 4 additions & 2 deletions pymisp/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -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: Optional[float, Tuple[float, float]]=None):
if not url:
raise NoURL('Please provide the URL of your MISP instance.')
if not key:
Expand All @@ -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: Optional[float, Tuple[float, float]] = timeout

self.global_pythonify = False

Expand Down Expand Up @@ -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)'''
Expand Down