mirror of https://github.com/MISP/PyMISP
Merge branch 'master' of github.com:MISP/PyMISP
commit
efed003302
|
@ -236,7 +236,7 @@ class PyMISP(object):
|
||||||
|
|
||||||
return messages
|
return messages
|
||||||
|
|
||||||
def _check_response(self, response):
|
def _check_response(self, response, lenient_response_type=False):
|
||||||
"""Check if the response from the server is not an unexpected error"""
|
"""Check if the response from the server is not an unexpected error"""
|
||||||
try:
|
try:
|
||||||
json_response = response.json()
|
json_response = response.json()
|
||||||
|
@ -244,7 +244,10 @@ class PyMISP(object):
|
||||||
# If the server didn't return a JSON blob, we've a problem.
|
# If the server didn't return a JSON blob, we've a problem.
|
||||||
if not len(response.text):
|
if not len(response.text):
|
||||||
raise PyMISPEmptyResponse('The server returned an empty response. \n{}\n{}\n'.format(response.request.headers, response.request.body))
|
raise PyMISPEmptyResponse('The server returned an empty response. \n{}\n{}\n'.format(response.request.headers, response.request.body))
|
||||||
raise PyMISPError(everything_broken.format(response.request.headers, response.request.body, response.text))
|
if lenient_response_type and not response.headers.get('content-type').startswith('application/json;'):
|
||||||
|
return response.text
|
||||||
|
else:
|
||||||
|
raise PyMISPError(everything_broken.format(response.request.headers, response.request.body, response.text))
|
||||||
|
|
||||||
errors = []
|
errors = []
|
||||||
|
|
||||||
|
@ -445,7 +448,7 @@ class PyMISP(object):
|
||||||
if isinstance(data, dict):
|
if isinstance(data, dict):
|
||||||
data = json.dumps(data)
|
data = json.dumps(data)
|
||||||
response = self._prepare_request('POST', url, data)
|
response = self._prepare_request('POST', url, data)
|
||||||
return self._check_response(response)
|
return self._check_response(response, lenient_response_type=True)
|
||||||
|
|
||||||
# ##############################################
|
# ##############################################
|
||||||
# ############### Event handling ###############
|
# ############### Event handling ###############
|
||||||
|
|
|
@ -62,7 +62,7 @@ class ExpandedPyMISP(PyMISP):
|
||||||
else:
|
else:
|
||||||
return value
|
return value
|
||||||
|
|
||||||
def _check_response(self, response):
|
def _check_response(self, response, lenient_response_type=False):
|
||||||
"""Check if the response from the server is not an unexpected error"""
|
"""Check if the response from the server is not an unexpected error"""
|
||||||
if response.status_code >= 500:
|
if response.status_code >= 500:
|
||||||
logger.critical(everything_broken.format(response.request.headers, response.request.body, response.text))
|
logger.critical(everything_broken.format(response.request.headers, response.request.body, response.text))
|
||||||
|
@ -84,6 +84,8 @@ class ExpandedPyMISP(PyMISP):
|
||||||
response = response['response']
|
response = response['response']
|
||||||
return response
|
return response
|
||||||
except Exception:
|
except Exception:
|
||||||
|
if lenient_response_type and not response.headers.get('content-type').startswith('application/json;'):
|
||||||
|
return response.text
|
||||||
if logger.isEnabledFor(logging.DEBUG):
|
if logger.isEnabledFor(logging.DEBUG):
|
||||||
logger.debug(response.text)
|
logger.debug(response.text)
|
||||||
if not len(response.content):
|
if not len(response.content):
|
||||||
|
|
Loading…
Reference in New Issue