Skip to content

Commit

Permalink
Add debug option
Browse files Browse the repository at this point in the history
  • Loading branch information
Rafiot committed Nov 25, 2015
1 parent 654f238 commit a334055
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
12 changes: 10 additions & 2 deletions pymisp/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ class PyMISP(object):
:param out_type: Type of object (json or xml)
"""

def __init__(self, url, key, ssl=True, out_type='json'):
def __init__(self, url, key, ssl=True, out_type='json', debug=False):
if not url:
raise NoURL('Please provide the URL of your MISP instance.')
if not key:
Expand All @@ -99,6 +99,7 @@ def __init__(self, url, key, ssl=True, out_type='json'):
self.key = key
self.ssl = ssl
self.out_type = out_type
self.debug = debug

self.categories = ['Internal reference', 'Targeting data', 'Antivirus detection',
'Payload delivery', 'Payload installation', 'Artifacts dropped',
Expand Down Expand Up @@ -144,10 +145,17 @@ def __prepare_session(self, force_out=None):
def _check_response(self, response):
if response.status_code >= 500:
response.raise_for_status()
to_return = response.json()
try:
to_return = response.json()
except:
if self.debug:
print(response.text)
raise PyMISPError('Unknown error: {}'.format(response.text))
if 400 <= response.status_code < 500:
if to_return.get('error') is None:
to_return['error'] = to_return.get('message')
if self.debug:
print(json.dumps(to_return, indent=4))
return to_return

# ################################################
Expand Down
3 changes: 2 additions & 1 deletion tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,12 @@

import unittest


class TestBasic(unittest.TestCase):

def setUp(self):
self.maxDiff = None
self.misp = PyMISP(url, key, True, 'json')
self.misp = PyMISP(url, key, True, 'json', True)

def _clean_event(self, event):
event['Event'].pop('uuid', None)
Expand Down

0 comments on commit a334055

Please sign in to comment.