Splunk Dev

Python script will only succeed every now and again

ssauler
New Member

Hi,

I wrote a Python script to retrieve JSON data from a REST API. The script fetches the JSON with the urllib2-module and does some parsing with the json-module. When I call the Python-script directly via the command line, it will always succeed.

However, if I'm calling it with Splunk's Python via /opt/splunk/bin/splunk cmd python /path/to/myscript.py, the script will only work on every third or fourth run. It will fail when retrieving the data with HTTP Error 400.

Used imports in the script: os, os.path, re, ast, csv, sys, json, logging, argparse, ConfigParser, urllib2

Do you have an idea what might be happening here? How can I troubleshoot this?
Many thanks!

It fails with Splunk 6.1.3 and its Python 2.7
Script works fine with OS Python 2.6.9

0 Karma

Damien_Dallimor
Ultra Champion

No need to reinvent the wheel. Use the REST API Modular Input.

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 ...