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