splunk-sdk-python icon indicating copy to clipboard operation
splunk-sdk-python copied to clipboard

XML Parser Issue - Splunk Enterprise

Open JuxhinDB opened this issue 8 years ago • 2 comments

Versions

Python: 3.6.3 Splunk Python SDK: 1.6.5

Splunk Enterprise: 7.1.2 Splunk Build: a0c72a66db66

Documentation Ref: http://docs.splunk.com/DocumentationStatic/PythonSDK/1.6.5/client.html#splunklib.client.Inputs


Description

I am currently trying to get a simply Proof-of-Concept to integrate some tools with Splunk via the Python SDK. Main Splunk server is listening on standard 80 and with the following code:

from splunklib import client

HOST = 'localhost'
UNAME = 'admin'
PASSWORD = 'redacted'


def main():
    _client = client.connect(
        host=HOST,
        port=80,
        username=UNAME,
        password=PASSWORD,
        verify=False,
        scheme='http'
    )

    assert isinstance(_client, client.Service)

    inputs = _client.inputs

    for item in inputs:
        print("[!] Input - Name: {}\tKind: {}".format(item.name, item.kind))


if __name__ == '__main__':
    main()

It appears that splunklib.binding.py is crashing on session = XML(body).findtext("./sessionKey") due to an invalid HTML response. The response is:

b'<!doctype html><html><head><meta http-equiv="content-type" content="text/html; charset=UTF-8"><meta http-equiv="refresh" content="1;url=http://localhost/en-US/services/auth/login"><title>303 See Other</title></head><body><h1>See Other</h1><p>The resource has moved temporarily <a href="http://localhost/en-US/services/auth/login">here</a>.</p></body></html>\r\n'

When mocking the response, I can get something going, but it still doesn't work as expected.

https://github.com/splunk/splunk-sdk-python/blob/39b18153f1a218caf345bc579a77cf0b9bbe9e99/splunklib/binding.py#L863-L866

The above block should maybe decode the string to bytes first, then encode the data, before passing it through the XML parser. If this is an agreed approach, I can go ahead and push a PR for it.

JuxhinDB avatar Sep 13 '18 14:09 JuxhinDB

这个问题已经解决了吗?我在1.7.3版本仍然遇到

gaojunxin avatar Mar 19 '23 03:03 gaojunxin

@gaojunxin I do not know unfortunately. If I recall correctly we were able to resolve this at the time via the API.

JuxhinDB avatar Mar 19 '23 09:03 JuxhinDB