Splunk Search

login using python sdk failed (http, not https)

hxzq2018
New Member

linux(RHEL 6.5 )
Python 2.7.15+splunk-sdk-python-1.6.5
http(not https)
code:

from splunklib.client import connect

def main():
    service = connect(host='10.xx.xx.75', port=8089,
                       username='admin', password='password', scheme='http')
    appdb = service.apps['splunk_app_db_connect']
    appdb.reload()

if __name__ == "__main__":
    main()


error info:

Traceback (most recent call last):
  File "app_enable.py", line 10, in 
    main()
  File "app_enable.py", line 5, in main
    username='admin', password='changeme', scheme='http')
  File "/usr/local/lib/python2.7/site-packages/splunk_sdk-1.6.4-py2.7.egg/splunklib/client.py", line 325, in connect
    s.login()
  File "/usr/local/lib/python2.7/site-packages/splunk_sdk-1.6.4-py2.7.egg/splunklib/binding.py", line 861, in login
    cookie="1") # In Splunk 6.2+, passing "cookie=1" will return the "set-cookie" header
  File "/usr/local/lib/python2.7/site-packages/splunk_sdk-1.6.4-py2.7.egg/splunklib/binding.py", line 1208, in post
    return self.request(url, message)
  File "/usr/local/lib/python2.7/site-packages/splunk_sdk-1.6.4-py2.7.egg/splunklib/binding.py", line 1225, in request
    response = self.handler(url, message, **kwargs)
  File "/usr/local/lib/python2.7/site-packages/splunk_sdk-1.6.4-py2.7.egg/splunklib/binding.py", line 1369, in request
    response = connection.getresponse()
  File "/usr/local/lib/python2.7/httplib.py", line 1121, in getresponse
    response.begin()
  File "/usr/local/lib/python2.7/httplib.py", line 438, in begin
    version, status, reason = self._read_status()
  File "/usr/local/lib/python2.7/httplib.py", line 394, in _read_status
    line = self.fp.readline(_MAXLINE + 1)
  File "/usr/local/lib/python2.7/socket.py", line 480, in readline
    data = self._sock.recv(self._rbufsize)
socket.error: [Errno 104] Connection reset by peer

error info in /opt/splunk/var/log/splunk/splunkd.log

11-30-2018 14:19:58.964 +0800 WARN HttpListener - Socket error from 10.xx.xx.75 while idling: error:1408F10B:SSL routines:SSL3_GET_RECORD:wrong version number

Tags (1)
0 Karma

MuS
SplunkTrust
SplunkTrust

Hi hxzq2018,

Splunk's management port 8089 is SSL enabled by default, hence the error message.
To make this work you need to use https/SSL in your script as well.

Hope this helps ...

cheers, MuS

0 Karma

hxzq2018
New Member

If i use scheme='https' , it return error below;
Traceback (most recent call last):
File "app_enable.py", line 10, in
main()
File "app_enable.py", line 5, in main
username='admin', password='changeme', scheme='https')
File "/usr/local/lib/python2.7/site-packages/splunk_sdk-1.6.4-py2.7.egg/splunklib/client.py", line 325, in connect
s.login()
File "/usr/local/lib/python2.7/site-packages/splunk_sdk-1.6.4-py2.7.egg/splunklib/binding.py", line 861, in login
cookie="1") # In Splunk 6.2+, passing "cookie=1" will return the "set-cookie" header
File "/usr/local/lib/python2.7/site-packages/splunk_sdk-1.6.4-py2.7.egg/splunklib/binding.py", line 1208, in post
return self.request(url, message)
File "/usr/local/lib/python2.7/site-packages/splunk_sdk-1.6.4-py2.7.egg/splunklib/binding.py", line 1225, in request
response = self.handler(url, message, **kwargs)
File "/usr/local/lib/python2.7/site-packages/splunk_sdk-1.6.4-py2.7.egg/splunklib/binding.py", line 1366, in request
connection.request(method, path, body, head)
File "/usr/local/lib/python2.7/httplib.py", line 1042, in request
self.send_request(method, url, body, headers)
File "/usr/local/lib/python2.7/httplib.py", line 1082, in _send_request
self.endheaders(body)
File "/usr/local/lib/python2.7/httplib.py", line 1038, in endheaders
self._send_output(message_body)
File "/usr/local/lib/python2.7/httplib.py", line 882, in _send_output
self.send(msg)
File "/usr/local/lib/python2.7/httplib.py", line 844, in send
self.connect()
File "/usr/local/lib/python2.7/httplib.py", line 1263, in connect
server_hostname=server_hostname)
File "/usr/local/lib/python2.7/ssl.py", line 369, in wrap_socket
_context=self)
File "/usr/local/lib/python2.7/ssl.py", line 617, in __init
_
self.do_handshake()
File "/usr/local/lib/python2.7/ssl.py", line 846, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [SSL] EC lib (_ssl.c:726)

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!

Get Agentic with Splunk Lantern: Connect to Cisco Cloud Control, Transform ...

Splunk Lantern is Splunk’s customer success center that provides practical guidance from Splunk experts on key ...

July Community Events: Master ITSI 5.0 & Automate Splunk

Struggling with alert fatigue or feeling like you're spending more time on infrastructure maintenance than ...

New Release of Federated Search: Bringing Splunk Analytics to More of Your Data

Organizations today are generating more data than ever and storing it across cloud object stores, data lakes, ...