Getting Data In

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

manudbc
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

manudbc
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

manudbc
Explorer

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

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

0 Karma
Get Updates on the Splunk Community!

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...