Building for the Splunk Platform

In Splunk SDK, why is my query causing the following error: "Unknown Command Index Error"

New Member

Hi Guys,

I am using Splunk SDK to export a query to get the following data:

import time
import splunklib.client as client
import splunklib.results as results
import json
import requests
from dateutil.parser import parse

HOST = "xxxx"
PORT = xxxx
USERNAME = "xxxx"
PASSWORD = "xxxx"

service = client.connect(

query='index=*    earliest=-5m        | regex "(?i)\D(?:0[1-9]|[12]\d|3[01])([\/.-])(?:0[1-9]|1[1-9])\1(?:19)\d\d|(?:19)\d\d([\/.-])(?:0[1-9]|[12]\d|3[01])([\/.-])(?:0[1-9]|[12]\d|3[01])\D" | rex "(?i)(?(19\d\d([\/.-])\d\d([\/.-])\d{1,2})|(\d\d([\/.-])\d{1,2}([\/.-])19\d\d))"|search dob=* AND dob!="1969-12-31"| table dob _raw index host source| stats first(dob) first(_raw) by index host source' 

while True:

    rr = results.ResultsReader(
    for result in rr:
0 Karma



you have to start the query with a regular spl command: search index=...

In the UI this is automatically inserted (but not shown).

All the best,

Get Updates on the Splunk Community!

Splunk Observability Cloud | Customer Survey!

If you use Splunk Observability Cloud, we invite you to share your valuable insights with us through a brief ...

Happy CX Day, Splunk Community!

Happy CX Day, Splunk Community! CX stands for Customer Experience, and today, October 3rd, is CX Day — a ...

.conf23 | Get Your Cybersecurity Defense Analyst Certification in Vegas

We’re excited to announce a new Splunk certification exam being released at .conf23! If you’re going to Las ...