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
Got questions? Get answers!

Join the Splunk Community Slack to learn, troubleshoot, and make connections with fellow Splunk practitioners in real time!

Meet up IRL or virtually!

Join Splunk User Groups to connect and learn in-person by region or remotely by topic or industry.

Get Updates on the Splunk Community!

Announcing Modern Navigation: A New Era of Splunk User Experience

We are excited to introduce the Modern Navigation feature in the Splunk Platform, available to both cloud and ...

Modernize your Splunk Apps – Introducing Python 3.13 in Splunk

We are excited to announce that the upcoming releases of Splunk Enterprise 10.2.x and Splunk Cloud Platform ...

Step into “Hunt the Insider: An Splunk ES Premier Mystery” to catch a cybercriminal ...

After a whole week of being on call, you fell asleep on your keyboard, and you hit a sequence of buttons that ...