Splunk Dev

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(service.jobs.export(query))
    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 | Unified Identity - Now Available for Existing Splunk ...

Raise your hand if you’ve already forgotten your username or password when logging into an account. (We can’t ...

Index This | How many sides does a circle have?

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

Registration for Splunk University is Now Open!

Are you ready for an adventure in learning?   Brace yourselves because Splunk University is back, and it's ...