splunk / splunk-sdk-python

Splunk Software Development Kit for Python
http://dev.splunk.com
Apache License 2.0
698 stars 370 forks source link

API Endpoint breaks on output_mode="Json" #357

Closed christoffertoft closed 3 years ago

christoffertoft commented 4 years ago

Describe the bug When calling service.apps.list() with output_mode="json", Etree cannot parse the results:

To Reproduce Steps to reproduce the behavior: Initialize a connection to your Splunk Search Head and call service.apps with output_mode = "json":

s = splunklib.client.connect(host=myhost ... )
s.apps.list(output_mode="json")
Traceback (most recent call last):
  File "<console>", line 1, in <module>
  File "/usr/local/lib/python3.6/site-packages/splunklib/client.py", line 1479, in list
    return list(self.iter(count=count, **kwargs))
  File "/usr/local/lib/python3.6/site-packages/splunklib/client.py", line 1439, in iter
    items = self._load_list(response)
  File "/usr/local/lib/python3.6/site-packages/splunklib/client.py", line 1345, in _load_list
    entries = _load_atom_entries(response)
  File "/usr/local/lib/python3.6/site-packages/splunklib/client.py", line 208, in _load_atom_entries
    r = _load_atom(response)
  File "/usr/local/lib/python3.6/site-packages/splunklib/client.py", line 203, in _load_atom
    .decode('utf-8', 'xmlcharrefreplace'), match)
  File "/usr/local/lib/python3.6/site-packages/splunklib/data.py", line 85, in load
    root = XML(text)
  File "/usr/local/lib/python3.6/xml/etree/ElementTree.py", line 1314, in XML
    parser.feed(text)
  File "<string>", line None
xml.etree.ElementTree.ParseError: not well-formed (invalid token): line 1, column 0

Expected behavior Should return a list of the Application objects but json formed, like a call to s.apps.list() would:

s.apps.list() [<splunklib.client.Application object at 0x7f0f00b7ff60>, <splunklib.client.Application object at 0x7f0f00b7feb8>, <splunklib.client.Application object at 0x7f0f00b7fef0>, <splunklib.client.Application object at 0x7f0f00b7fe48>, <splunklib.client.Application object at 0x7f0f00b7fe10>, <splunklib.client.Application object at 0x7f0f00b7fdd8>, <splunklib.client.Application object at 0x7f0f00be7a20>, <splunklib.client.Application object at 0x7f0f00be7a58>]

Logs or Screenshots If applicable, add logs or screenshots to help explain your problem.

Splunk

SDK splunk-sdk 1.6.14 splunklib 1.0.0 Python 3.6.5

ncanumalla-splunk commented 3 years ago

@christoffertoft This SDK does not support Json output_mode but only XML output. Can you please provide more details where you expect Json results and why you used the output_mode as Json?

ashah-splunk commented 3 years ago

@christoffertoft Closing this issue due to no response on it. Please reopen if this is still an issue.