Splunk Dev

"no element found" error connecting to Splunk Server using Python SDK

Nsplk
Engager

Splunk Team,

I’m trying to connect to splunk server using Splunk SDK for python and having following error which I’m unable to debug.
Can you please advise and steer me in the right direction.

File "connect_splk.py", line 17, in 
    password=PASSWORD)
  File "/usr/lib/python2.7/site-packages/splunklib/client.py", line 321, in connect
    s.login()
  File "/usr/lib/python2.7/site-packages/splunklib/binding.py", line 860, in login
    session = XML(body).findtext("./sessionKey")
  File "/usr/lib64/python2.7/xml/etree/ElementTree.py", line 1312, in XML
    return parser.close()
  File "/usr/lib64/python2.7/xml/etree/ElementTree.py", line 1665, in close
    self._raiseerror(v)
  File "/usr/lib64/python2.7/xml/etree/ElementTree.py", line 1517, in _raiseerror
    raise err
xml.etree.ElementTree.ParseError: no element found: line 1, column 0

Code:

import splunklib.client as client
HOST = ""
PORT = “”
USERNAME = ""
PASSWORD = ""
# Create a Service instance and log in 
service = client.connect(
    host=HOST,
    port=PORT,
    username=USERNAME,
    password=PASSWORD)
# Printing installed apps to the console to verify login
for app in service.apps:
    print app.name;

Please advise.
Nidhi

harsmarvania57
Ultra Champion

Hi @Nslpk,

Are you supplying hostname, port, username and password in below code in your python script ?

HOST = ""
PORT = “”
USERNAME = ""
PASSWORD = ""

It should be something like this, but you need to change parameter values according to your environment.

HOST = "localhost"
PORT = 8089
USERNAME = "admin"
PASSWORD = "changeme"
0 Karma

Nsplk
Engager

Yes I'm supplying all mentioned above and required.

-Nidhi

0 Karma
Get Updates on the Splunk Community!

Introducing the 2024 SplunkTrust!

Hello, Splunk Community! We are beyond thrilled to announce our newest group of SplunkTrust members!  The ...

Introducing the 2024 Splunk MVPs!

We are excited to announce the 2024 cohort of the Splunk MVP program. Splunk MVPs are passionate members of ...

Splunk Custom Visualizations App End of Life

The Splunk Custom Visualizations apps End of Life for SimpleXML will reach end of support on Dec 21, 2024, ...