Splunk Dev

splunk - python - requests.post Authentication error

vamsigurram
Path Finder

The below code is throwing error.

{"messages":[{"type":"WARN","text":"call not properly authenticated"}]}

 

r = requests.get(base_url+"/servicesNS/admin/search/auth/login"data={'username':username,'password':password}, verify=False)

    sessionkey = minidom.parseString(r.text).getElementsByTagName('sessionKey')[0].firstChild.nodeValue
    print ("Session Key:", sessionkey)
 
Output:
Session Key: im0t_JBlWSnQnaWwFCj016^q_QEYutHbpQMBGLEHlxOesSAVh6iQ0X8Y4tcoQR5a4lwr3I2ayDgBVNx0412THyMkON0iO6^Af_2DCYS1F8Eseo
 
I see Session Key here. No issues so far.
 
But when I pass the above session key, to the below requests.post, I see the error.
What am I doing wrong here?
    
url = base_url + "/services/search/jobs?output_mode=json"
    headers = {
    "content-type""application/x-www-form-urlencoded",    
    "Authorization""Splunk %s" % sessionkey,           
    }
    payload = {
        "search""|rest /servicesNS/%s/search/directory" % kouser,
        "count"0
    }
    r = requests.post(url, headers=headers, data=payload, verify = False)
    print(r.text)
 
{"messages":[{"type":"WARN","text":"call not properly authenticated"}]}
 
 
Is there anything wrong here?
Labels (2)
0 Karma
Get Updates on the Splunk Community!

Leveraging Automated Threat Analysis Across the Splunk Ecosystem

Enhance Security Operations with Automated Threat Analysis in the Splunk EcosystemAre you leveraging ...

Splunk Developers: Go Beyond the Dashboard with These .Conf25 Sessions

  Whether you’re building custom apps, diving into SPL2, or integrating AI and machine learning into your ...

Index This | How do you write 23 only using the number 2?

July 2025 Edition Hayyy Splunk Education Enthusiasts and the Eternally Curious!  We’re back with this month’s ...