Merge pull request #11 from iglocska/xml_json_fix

Fix to an issue with using XML as input for add_event() and update_ev…
pull/2/merge
Alexandre Dulaunoy 2015-07-30 15:37:51 +02:00
commit 389f88ce8b
2 changed files with 4 additions and 3 deletions

View File

@ -4,6 +4,7 @@
import sys import sys
from pymisp import PyMISP from pymisp import PyMISP
import json
from keys import cert, priv from keys import cert, priv
@ -30,7 +31,7 @@ def init(cert_to_priv=True):
def _to_utf8(request): def _to_utf8(request):
to_return = None to_return = None
if 'json' in request.headers['content-type']: if 'json' in request.headers['content-type']:
to_return = request.json() to_return = json.dumps(request.json())
else: else:
to_return = request.text.encode('utf-8') to_return = request.text.encode('utf-8')
return to_return return to_return

View File

@ -84,7 +84,7 @@ class PyMISP(object):
:param event: Event object to add :param event: Event object to add
""" """
session = self.__prepare_session() session = self.__prepare_session()
return session.post(self.url, data=json.dumps(event)) return session.post(self.url, data=event)
def update_event(self, event_id, event): def update_event(self, event_id, event):
""" """
@ -94,7 +94,7 @@ class PyMISP(object):
:param event: Elements to add :param event: Elements to add
""" """
session = self.__prepare_session() session = self.__prepare_session()
return session.post(self.rest.format(event_id), data=json.dumps(event)) return session.post(self.rest.format(event_id), data=event)
def delete_event(self, event_id): def delete_event(self, event_id):
""" """