Open
ghost
opened this issue 8 years ago
•
12 comments
Hi,
i'm getting SSLError while connecting splunk using python splunk sdk.
Code:
from splunklib import client
splunk_service=client.connect(host="localhost",port=8000,username="admin",password="*********")
print (splunk_service)
python version:
2.7.15
splunk sdk version : 1.6.5
Error:
Traceback (most recent call last):
File "splunk_python.py", line 9, in
username='admin', password='kasi@777')
File "C:\Python27\lib\site-packages\splunklib\client.py", line 325, in connect
s.login()
File "C:\Python27\lib\site-packages\splunklib\binding.py", line 861, in login
cookie="1") # In Splunk 6.2+, passing "cookie=1" will return the "set-cookie" header
File "C:\Python27\lib\site-packages\splunklib\binding.py", line 1208, in post
return self.request(url, message)
File "C:\Python27\lib\site-packages\splunklib\binding.py", line 1225, in request
response = self.handler(url, message, **kwargs)
File "C:\Python27\lib\site-packages\splunklib\binding.py", line 1366, in request
connection.request(method, path, body, head)
File "C:\Python27\lib\httplib.py", line 1042, in request
self._send_request(method, url, body, headers)
File "C:\Python27\lib\httplib.py", line 1082, in _send_request
self.endheaders(body)
File "C:\Python27\lib\httplib.py", line 1038, in endheaders
self._send_output(message_body)
File "C:\Python27\lib\httplib.py", line 882, in _send_output
self.send(msg)
File "C:\Python27\lib\httplib.py", line 844, in send
self.connect()
File "C:\Python27\lib\httplib.py", line 1263, in connect
server_hostname=server_hostname)
File "C:\Python27\lib\ssl.py", line 363, in wrap_socket
_context=self)
File "C:\Python27\lib\ssl.py", line 611, in init
self.do_handshake()
File "C:\Python27\lib\ssl.py", line 840, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [SSL: UNKNOWN_PROTOCOL] unknown protocol (_ssl.c:661)
@JuxhinDB Tried what you mentioned above , but getting below error
Traceback (most recent call last):
File "check_splunk_conn.py", line 15, in
scheme='http'
File "/usr/local/lib/python2.7/site-packages/splunklib/client.py", line 331, in connect
s.login()
File "/usr/local/lib/python2.7/site-packages/splunklib/binding.py", line 875, in login
session = XML(body).findtext("./sessionKey")
File "/usr/lib64/python2.7/xml/etree/ElementTree.py", line 1300, in XML
parser.feed(text)
File "/usr/lib64/python2.7/xml/etree/ElementTree.py", line 1642, in feed
self._raiseerror(v)
File "/usr/lib64/python2.7/xml/etree/ElementTree.py", line 1506, in _raiseerror
raise err
xml.etree.ElementTree.ParseError: syntax error: line 1, column 0
@Shrikant1234 that seems to be a different issue entirely. To troubleshoot it I would pass the client through a proxy such as Burp or Fiddler. Haven't touched this library in a very long time but maybe you can configure the proxy as follows:
service = client.connect(host='10.0.172.11', port=8000,username='virus-reporter', password='123456789', verify=False)
Traceback (most recent call last):
File "", line 1, in
File "C:\Program Files\Python37\lib\site-packages\splunklib\client.py", line 331, in connect
s.login()
File "C:\Program Files\Python37\lib\site-packages\splunklib\binding.py", line 872, in login
cookie="1") # In Splunk 6.2+, passing "cookie=1" will return the "set-cookie" header
File "C:\Program Files\Python37\lib\site-packages\splunklib\binding.py", line 1224, in post
return self.request(url, message)
File "C:\Program Files\Python37\lib\site-packages\splunklib\binding.py", line 1241, in request
response = self.handler(url, message, **kwargs)
File "C:\Program Files\Python37\lib\site-packages\splunklib\binding.py", line 1382, in request
connection.request(method, path, body, head)
File "C:\Program Files\Python37\lib\http\client.py", line 1229, in request
self._send_request(method, url, body, headers, encode_chunked)
File "C:\Program Files\Python37\lib\http\client.py", line 1275, in _send_request
self.endheaders(body, encode_chunked=encode_chunked)
File "C:\Program Files\Python37\lib\http\client.py", line 1224, in endheaders
self._send_output(message_body, encode_chunked=encode_chunked)
File "C:\Program Files\Python37\lib\http\client.py", line 1016, in _send_output
self.send(msg)
File "C:\Program Files\Python37\lib\http\client.py", line 956, in send
self.connect()
File "C:\Program Files\Python37\lib\http\client.py", line 1392, in connect
server_hostname=server_hostname)
File "C:\Program Files\Python37\lib\ssl.py", line 412, in wrap_socket
session=session
File "C:\Program Files\Python37\lib\ssl.py", line 850, in _create
self.do_handshake()
File "C:\Program Files\Python37\lib\ssl.py", line 1108, in do_handshake
self._sslobj.do_handshake()
ssl.SSLError: [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1045)
Hi Everyone,
I am facing the same issue.
I am using port 8089.
Here is my error:
Traceback (most recent call last):
File "test.py", line 13, in
password=pwd)
File "/Library/Python/2.7/site-packages/splunklib/client.py", line 331, in connect
s.login()
File "/Library/Python/2.7/site-packages/splunklib/binding.py", line 872, in login
cookie="1") # In Splunk 6.2+, passing "cookie=1" will return the "set-cookie" header
File "/Library/Python/2.7/site-packages/splunklib/binding.py", line 1224, in post
return self.request(url, message)
File "/Library/Python/2.7/site-packages/splunklib/binding.py", line 1241, in request
response = self.handler(url, message, **kwargs)
File "/Library/Python/2.7/site-packages/splunklib/binding.py", line 1382, in request
connection.request(method, path, body, head)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 1053, in request
self._send_request(method, url, body, headers)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 1093, in _send_request
self.endheaders(body)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 1049, in endheaders
self._send_output(message_body)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 893, in _send_output
self.send(msg)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 855, in send
self.connect()
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 1266, in connect
HTTPConnection.connect(self)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/httplib.py", line 832, in connect
self.timeout, self.source_address)
File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/socket.py", line 575, in create_connection
raise err
socket.error: [Errno 61] Connection refused
@JuxhinDB Tried what you mentioned above , but getting below error
Traceback (most recent call last):
File "check_splunk_conn.py", line 15, in
scheme='http'
File "/usr/local/lib/python2.7/site-packages/splunklib/client.py", line 331, in connect
s.login()
File "/usr/local/lib/python2.7/site-packages/splunklib/binding.py", line 875, in login
session = XML(body).findtext("./sessionKey")
File "/usr/lib64/python2.7/xml/etree/ElementTree.py", line 1300, in XML
parser.feed(text)
File "/usr/lib64/python2.7/xml/etree/ElementTree.py", line 1642, in feed
self._raiseerror(v)
File "/usr/lib64/python2.7/xml/etree/ElementTree.py", line 1506, in _raiseerror
raise err
xml.etree.ElementTree.ParseError: syntax error: line 1, column 0
I'm getting this error, and cause is that the server, when trying to login returns a redirect and the code can't handle that:
To server:
POST /services/auth/login HTTP/1.1
Accept-Encoding: identity
Content-Length: 42
Host: localhost
User-Agent: splunk-sdk-python/1.6.11
Accept: */*
Connection: Close
username=admin&password=********&cookie=1
Response:
HTTP/1.1 303 See Other
Date: Fri, 20 Dec 2019 17:12:44 GMT
Content-Type: text/html; charset=UTF-8
X-Content-Type-Options: nosniff
Content-Length: 359
Location: http://localhost/en-US/services/auth/login
Vary: Accept-Language
Connection: Close
X-Frame-Options: SAMEORIGIN
Server: Splunkd
<!doctype html>
...
The code doesn't appear to handle this and tries to find a sessionKey and fails. The odd thing is that the comments in the code clearly state that it should follow 303 redirects, I can't find the actual code that should do it.
Hi @kleptog , could you please verify which port and scheme are being set in the configuration before calling the connect service.
The connect service works properly when port = 8089 and scheme=https. Default value for scheme is 'https' if not set explicitly. Please try using the port = 8089 and scheme=https configuration and let us know if you still face the error