Archive

ERROR ExecProcessor - message from "script.py" Error: cannot serialize {json}

Explorer

Hi,
I have a Script which download a Json, it look like:
def stream_events(self, inputs, ew):
ew.log("INFO","Adding data")
for input_name, input_item in inputs.inputs.iteritems():
api = input_item["api"]

                        try:
                                r = requests.get("URL".format(api))
                                t = json.loads(r.content)
                        except Exception as e:
                                ew.log("ERROR", "Error: %s" % str(e))

                        try:
                                for elements in t['notifications']:
                                        logevent = Event()
                                        logevent.stanza = input_name
                                        logevent.data = elements
                                        ew.write_event(logevent)
                        except Exception as e:
                                ew.log("ERROR", "Error: %s" % str(e))

And I having thaths error in index= "__internals":
ERROR ExecProcessor - message from "script.py" Error: cannot serialize {json}

How can I solve It?

Tags (2)
0 Karma
1 Solution

Explorer

Solved
It was a problem in this line:
logevent.data = elements

Solved line:
logevent.data = json.dumps(elements, sort_keys=True, separators=(',',':'))

View solution in original post

0 Karma

Explorer

Solved
It was a problem in this line:
logevent.data = elements

Solved line:
logevent.data = json.dumps(elements, sort_keys=True, separators=(',',':'))

View solution in original post

0 Karma