Splunk Dev

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

fetterman
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

chandrasekharko
Path Finder

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

turbocid
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

p_gurav
Champion

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

0 Karma

paramagurukarth
Builder

Yes port is his issue

fetterman
Engager

Ah, yes, makes sense. thanks!

0 Karma

chandrasekharko
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: CERTIFICATE_VERIFY_FAILED] 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

chandrasekharko
Path Finder

I got it never mind.

0 Karma

turbocid
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

chandrasekharko
Path Finder

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

0 Karma
Get Updates on the Splunk Community!

Webinar Recap | Revolutionizing IT Operations: The Transformative Power of AI and ML ...

The Transformative Power of AI and ML in Enhancing Observability   In the realm of IT operations, the ...

.conf24 | Registration Open!

Hello, hello! I come bearing good news: Registration for .conf24 is now open!   conf is Splunk’s rad annual ...

ICYMI - Check out the latest releases of Splunk Edge Processor

Splunk is pleased to announce the latest enhancements to Splunk Edge Processor.  HEC Receiver authorization ...