Developing for Splunk Enterprise
Highlighted

Why am I unable to connect to Splunk via SDK client.connect function?

Engager

I am following the Splunk SDK example using version 1.6.3 with Python 3, on Splunk 6.6.4:

import splunklib.client as client

HOST = "localhost"
PORT = 8000
USERNAME = "admin"
PASSWORD = "changeme"

service = client.connect(
    host=HOST,
    port=PORT,
    username=USERNAME,
    password=PASSWORD)

for app in service.apps:

print app.name
I have changed the hard-coded credentials to match valid login info, however I am receiving the following response:

Traceback (most recent call last):

  File "/opt/anaconda3/lib/python3.6/site-packages/IPython/core/interactiveshell.py", line 2862, in run_code
    exec(code_obj, self.user_global_ns, self.user_ns)

  File "", line 6, in 
    password=PASSWORD

  File "/opt/anaconda3/lib/python3.6/site-packages/splunk_sdk-1.6.3-py3.6.egg/splunklib/client.py", line 322, in connect
    s.login()

  File "/opt/anaconda3/lib/python3.6/site-packages/splunk_sdk-1.6.3-py3.6.egg/splunklib/binding.py", line 862, in login
    session = XML(body).findtext("./sessionKey")

  File "/opt/anaconda3/lib/python3.6/xml/etree/ElementTree.py", line 1314, in XML
    parser.feed(text)

  File "", line unknown
ParseError: syntax error: line 1, column 0
0 Karma
Highlighted

Re: Why am I unable to connect to Splunk via SDK client.connect function?

Champion

Check indentation in code. Also , port should be 8089 or (your splunk management port) not 8000.

0 Karma
Highlighted

Re: Why am I unable to connect to Splunk via SDK client.connect function?

Yes port is his issue

Highlighted

Re: Why am I unable to connect to Splunk via SDK client.connect function?

Engager

Ah, yes, makes sense. thanks!

0 Karma
Highlighted

Re: Why am I unable to connect to Splunk via SDK client.connect function?

Path Finder

I have the same issue. But, I used port 8089. But, I am still not able to connect. The error I get is:

ssl.SSLError: [SSL: CERTIFICATEVERIFYFAILED] certificate verify failed (_ssl.c:579)

The code is below for the connection I use. Please guide me here.

import splunklib.client as client

HOST = "localhost"
PORT = 8089
USERNAME = "admin"
PASSWORD = "Qwerty@1993"

service = client.connect(
host=HOST,
port=PORT,
username=USERNAME,
password=PASSWORD)

for app in service.apps:
print app.name

0 Karma
Highlighted

Re: Why am I unable to connect to Splunk via SDK client.connect function?

Path Finder

I got it never mind.

0 Karma
Highlighted

Re: Why am I unable to connect to Splunk via SDK client.connect function?

New Member

How did you fix this issue?
I also got same issue.
I use port 8000, as it is the port I connect to using web browser.
When I use port 8000, I got the same error msg as you.

I also tried port 8089 or 443, both will lead to different error messages:
ConnectionRefusedError,
which implies the port could be wrong

0 Karma
Highlighted

Re: Why am I unable to connect to Splunk via SDK client.connect function?

Path Finder

I by passed the SSL cert
run this command before execute the python script
export PYTHONHTTPSVERIFY=0

0 Karma
Highlighted

Re: Why am I unable to connect to Splunk via SDK client.connect function?

New Member

How did you fix this issue?
I also got same issue.
I use port 8000, as it is the port I connect to using web browser.
When I use port 8000, I got the same error msg as you.

I also tried port 8089 or 443, both will lead to different error messages:
ConnectionRefusedError,
which implies the port could be wrong

0 Karma
Highlighted

Re: Why am I unable to connect to Splunk via SDK client.connect function?

Path Finder

Try running this command before execute the python script to bypass the cert
export PYTHONHTTPSVERIFY=0