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!

Threat Hunting Unlocked: How to Uplevel Your Threat Hunting With the PEAK Framework ...

WATCH NOWAs AI starts tackling low level alerts, it's more critical than ever to uplevel your threat hunting ...

Splunk APM: New Product Features + Community Office Hours Recap!

Howdy Splunk Community! Over the past few months, we’ve had a lot going on in the world of Splunk Application ...

Index This | Forward, I’m heavy; backward, I’m not. What am I?

April 2024 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with another ...