Splunk Enterprise

Why is there Error 404 when using Splunk sdk python?

Julia1231
Communicator

Hi everyone,

I'm starting using Splunk SDK Python.

I'm using Python 3.8 and Splunk 9.0

I get error: HTTP 404 action forbidden. I don't understand why and how to fix it.

Here is my code: 

import splunklib.client as client

import splunklib.results as results

def connect_to_splunk(username, password, host='localhost', port='8089', owner='admin', app='search', sharing='user'):

try: service = client.connect(host=host, port=port, username=username, password=password, owner=owner, app=app, sharing=sharing)

if service:

print("Connected successfully!")

return service

except Exception as e:

print(e)

def run_normal_mode_search(splunk_service, search_string, payload={}):

try: job = splunk_service.jobs.create(search_string, **payload) # print(job.content)

# check if the job is completed or not

while True:

while not job.is_ready():

pass if job["isDone"] == "1":

break

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

print(result)

except Exception as e:

print(e)

def main():

try:

splunk_service = connect_to_splunk(username='xxx', password='xxx')

search_string = "search index= haindex1 |top host"

payload = {"exec_mode": "normal"}

run_normal_mode_search(splunk_service, search_string, payload)

except Exception as e:

print(e)

if _name_ == "_main_": main()



Here is the result:

Connected successfully!

HTTP 404 Not Found -- Action forbidden.

Process finished with exit code 0

 

Thanks and have a nice day!

Julia

 

Labels (2)
0 Karma

Lazarus
New Member

I have the same issue.

0 Karma
Get Updates on the Splunk Community!

.conf25 Registration is OPEN!

Ready. Set. Splunk! Your favorite Splunk user event is back and better than ever. Get ready for more technical ...

Detecting Cross-Channel Fraud with Splunk

This article is the final installment in our three-part series exploring fraud detection techniques using ...

Splunk at Cisco Live 2025: Learning, Innovation, and a Little Bit of Mr. Brightside

Pack your bags (and maybe your dancing shoes)—Cisco Live is heading to San Diego, June 8–12, 2025, and Splunk ...