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

Non breaking spaces break the is_ready() function

Open mew1033 opened this issue 8 years ago • 2 comments

I had a search that accidentally had non breaking spaces in it. When pasting it into the splunk search box, it works fine, albeit the character has a red highlight. But when I start the search with the sdk, then run is_ready() on the job, it crashes.

Here's the traceback:

Traceback (most recent call last):
  File "script.py", line 1172, in <module>
    main()
  File "script.py", line 745, in main
    while not splunk_search_job.is_ready():
  File "/usr/lib/python2.7/site-packages/splunklib/client.py", line 2705, in is_ready
    self._state = self.read(response)
  File "/usr/lib/python2.7/site-packages/splunklib/client.py", line 1086, in read
    results = self._load_state(response)
  File "/usr/lib/python2.7/site-packages/splunklib/client.py", line 949, in _load_state
    entry = self._load_atom_entry(response)
  File "/usr/lib/python2.7/site-packages/splunklib/client.py", line 2626, in _load_atom_entry
    return _load_atom(response).entry
  File "/usr/lib/python2.7/site-packages/splunklib/client.py", line 197, in _load_atom
    return data.load(response.body.read().decode('utf-8'), match)
  File "/usr/lib/python2.7/site-packages/splunklib/data.py", line 79, in load
    root = XML(text)
  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 1640, in feed
    self._parser.Parse(data, 0)
UnicodeEncodeError: 'ascii' codec can't encode character u'\xa0' in position 6754: ordinal not in range(128)

And here's the few characters that are throwing it off.

>>> s[5458:5470]
'ion is\xc2\xa0*not'

For reference, here's the piece of the script that is breaking:

while True:
    while not splunk_search_job.is_ready():
        pass
    if splunk_search_job['isDone'] == '1':
        break
    time.sleep(2)

mew1033 avatar Jul 31 '18 22:07 mew1033

Thanks for the bug report @mew1033 we'll take a look. We're open to a pull request if you're interested in taking this on

shakeelmohamed avatar Aug 01 '18 18:08 shakeelmohamed

Hi @mew1033, can you see if v1.6.5 fixes this for you? Please re-open if it doesn't

shakeelmohamed avatar Oct 08 '18 21:10 shakeelmohamed