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
SplunkTrust
SplunkTrust

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!

What's new in Splunk Cloud Platform 9.1.2312?

Hi Splunky people! We are excited to share the newest updates in Splunk Cloud Platform 9.1.2312! Analysts can ...

What’s New in Splunk Security Essentials 3.8.0?

Splunk Security Essentials (SSE) is an app that can amplify the power of your existing Splunk Cloud Platform, ...

Let’s Get You Certified – Vegas-Style at .conf24

Are you ready to level up your Splunk game? Then, let’s get you certified live at .conf24 – our annual user ...