Getting Data In

Not able to obtain search results via Splunk REST API

Path Finder


I am using Splunk Python SDK to connect to Splunk via REST API.

However the code I have written does not return any results:

query = 'search index = test | stats sum(bytes) as bytes by ip'
kwargs_oneshot = {"earliest_time": "-2m","latest_time": "now","enable_lookups":True,"rf":["ip"]}
job =, **kwargs_oneshot)
while not job.is_done():

for result in results.ResultsReader(job.results()):
    print (result)

If I remove "stats" command from the query, then I only get "_raw" data. What should i change in my code to get the "stats" command output?

Thank you.

0 Karma


I'm assumed your search is giving proper output on SH.

Have you tried reader?

import splunklib.results as results


# Run a one-shot search and display the results using the results reader

# Set the parameters for the search:
# - Search everything in a 24-hour time range starting June 19, 12:00pm
# - Display the first 10 results
kwargs_oneshot = {"earliest_time": "2014-06-19T12:00:00.000-07:00",
                  "latest_time": "2014-06-20T12:00:00.000-07:00"}
searchquery_oneshot = "search * | head 10"

oneshotsearch_results =, **kwargs_oneshot)

# Get the results and display them using the ResultsReader
reader = results.ResultsReader(oneshotsearch_results)
for item in reader:

0 Karma

Path Finder

Yes, i tried that.
When I run 'query = search index = test' i get the output in raw format.
However when I run 'query = search index = test | stats sum(bytes) as bytes by ip' I get none.

Running the search directly on the SH works fine.

0 Karma


Can you please try this search in python?

index = test | table _time _raw bytes ip

I just want to know about the fields are there or not. If we didn't find any fields then need to check extraction of fields or app context from which this search is executing.

0 Karma