UnicodeDecodeError: invalid continuation byte
If I iterate over events like this using the SDK:
for event in events:
and an event field contains: TELEF�NICA , it raises the following:
UnicodeDecodeError at "/opt/splunk/etc/apps/app_name/bin/splunklib/searchcommands/search_command.py", line 822 : 'utf8' codec can't decode byte 0xd4 in position 5: invalid continuation byte
Thanks for the bug report @doksu. Which versions of Python, the SDK, and Splunk are you using?
Python provided by Splunk Enterprise 6.4.4 and version 1.6.0 of the SDK.
Here's more detail:
2017-04-07 03:36:10,962, Level=ERROR, Pid=24770, Logger=splunklib, File=search_command.py, Line=971, UnicodeDecodeError at "/opt/splunk/etc/apps/TA-setops/bin/splunklib/searchcommands/search_command.py", line 822 : 'utf8' codec can't decode byte 0xd4 in position 5: invalid continuation byte
Traceback:
File "/opt/splunk/etc/apps/TA-setops/bin/splunklib/searchcommands/search_command.py", line 771, in _process_protocol_v2
self._execute(ifile, None)
File "/opt/splunk/etc/apps/TA-setops/bin/splunklib/searchcommands/eventing_command.py", line 54, in _execute
SearchCommand._execute(self, ifile, self.transform)
File "/opt/splunk/etc/apps/TA-setops/bin/splunklib/searchcommands/search_command.py", line 839, in _execute
self._record_writer.write_records(process(self._records(ifile)))
File "/opt/splunk/etc/apps/TA-setops/bin/splunklib/searchcommands/internals.py", line 519, in write_records
for record in records:
File "/opt/splunk/etc/apps/TA-setops/bin/distinctfields.py", line 45, in transform
for event in events:
File "/opt/splunk/etc/apps/TA-setops/bin/splunklib/searchcommands/search_command.py", line 949, in _records_protocol_v2
record[mv_fieldnames[fieldname]] = self._decode_list(value)
File "/opt/splunk/etc/apps/TA-setops/bin/splunklib/searchcommands/search_command.py", line 822, in _decode_list
return [match.replace('$$', '$') for match in SearchCommand._encoded_value.findall(mv)]
Hi @shakeelmohamed,
Just wondering about the status of this bug?
Thanks :)
@doksu thanks for following up. Our engineering resources are extremely tight at the moment. If you or someone else wants to send a pull request to the develop branch we're more than happy to review it
Thanks @shakeelmohamed. Not sure I'm going to have any time in the lead up to conf but I'll have a poke and send a pull request if possible.
Created internal ticket DVPL-7288
Overview
Hello.
This is a report to follow up on the findings of the bug that was filed in the git hub issues for the Splunk Python SDK regarding unicode searches.
This bug cannot be reproduced.
Steps
- Install Splunk 7.1.0
- Install Splunk Python SDK 1.6.3
- Upload both "test.csv" and "日本語.csv" to an index called "test_index"
- Execute the file "test_sdk.py"
Test Data
Current thread input
book_author,book_title
dunning krugger,TELEF�NICA
Japanese Input
本の作家,本のタイトル
ヒロザキ野村,この世界の戦い:環境が変わって一緒になにかをした方がいいです
アレクシロース,北風が寒いのに君の体で私が温まる
だれだれなになに,君の名前で私を呼びます
Test File
"""Example for testing"""
import splunklib.client as client
print "=" * 80
print "Beginning testing on Splunk Python SDK Version {}".format(splunklib.__version__)
print "=" * 80
print
HOST = "localhost"
PORT = 8089
USERNAME = "admin"
PASSWORD = "changeme"
# Create a Service instance and log in
service = client.connect(
host=HOST,
port=PORT,
username=USERNAME,
password=PASSWORD)
# Get the collection of search jobs
jobs = service.jobs
# Create a search job
kwargs_blockingsearch = {"exec_mode": "blocking"}
search_job = jobs.create('search index="test_index" *', **kwargs_blockingsearch)
xml_output = ""
for event in search_job.events():
xml_output += event
print xml_output
Output
<?xml version='1.0' encoding='UTF-8'?>
<results preview='0'>
<meta>
<fieldOrder>
<field>_bkt</field>
<field>_cd</field>
<field>_indextime</field>
<field>_raw</field>
<field>_serial</field>
<field>_si</field>
<field>_sourcetype</field>
<field>_time</field>
<field>host</field>
<field>index</field>
<field>linecount</field>
<field>source</field>
<field>sourcetype</field>
<field>splunk_server</field>
</fieldOrder>
</meta>
<result offset='0'>
<field k='_bkt'>
<value>
<text>test_index~0~5C062B0F-3DA5-41C5-9F21-D15A627EFC88</text>
</value>
</field>
<field k='_cd'>
<value>
<text>0:17</text>
</value>
</field>
<field k='_indextime'>
<value>
<text>1524765348</text>
</value>
</field>
<field k='_raw'>
<v xml:space='preserve' trunc='0'>だれだれなになに,君の名前で私を呼びます</v>
</field>
<field k='_serial'>
<value>
<text>0</text>
</value>
</field>
<field k='_si'>
<value>
<text>lknecht-mbpr15</text>
</value>
<value>
<text>test_index</text>
</value>
</field>
<field k='_sourcetype'>
<value>
<text>csv</text>
</value>
</field>
<field k='_time'>
<value>
<text>2018-04-26T10:55:48.000-07:00</text>
</value>
</field>
<field k='host'>
<value>
<text>lknecht-mbpr15</text>
</value>
</field>
<field k='index'>
<value>
<text>test_index</text>
</value>
</field>
<field k='linecount'>
<value>
<text>1</text>
</value>
</field>
<field k='source'>
<value>
<text>日本語.csv</text>
</value>
</field>
<field k='sourcetype'>
<value>
<text>csv</text>
</value>
</field>
<field k='splunk_server'>
<value>
<text>lknecht-mbpr15</text>
</value>
</field>
</result>
<result offset='1'>
<field k='_bkt'>
<value>
<text>test_index~0~5C062B0F-3DA5-41C5-9F21-D15A627EFC88</text>
</value>
</field>
<field k='_cd'>
<value>
<text>0:14</text>
</value>
</field>
<field k='_indextime'>
<value>
<text>1524765348</text>
</value>
</field>
<field k='_raw'>
<v xml:space='preserve' trunc='0'>アレクシロース,北風が寒いのに君の体で私が温まる</v>
</field>
<field k='_serial'>
<value>
<text>1</text>
</value>
</field>
<field k='_si'>
<value>
<text>lknecht-mbpr15</text>
</value>
<value>
<text>test_index</text>
</value>
</field>
<field k='_sourcetype'>
<value>
<text>csv</text>
</value>
</field>
<field k='_time'>
<value>
<text>2018-04-26T10:55:48.000-07:00</text>
</value>
</field>
<field k='host'>
<value>
<text>lknecht-mbpr15</text>
</value>
</field>
<field k='index'>
<value>
<text>test_index</text>
</value>
</field>
<field k='linecount'>
<value>
<text>1</text>
</value>
</field>
<field k='source'>
<value>
<text>日本語.csv</text>
</value>
</field>
<field k='sourcetype'>
<value>
<text>csv</text>
</value>
</field>
<field k='splunk_server'>
<value>
<text>lknecht-mbpr15</text>
</value>
</field>
</result>
<result offset='2'>
<field k='_bkt'>
<value>
<text>test_index~0~5C062B0F-3DA5-41C5-9F21-D15A627EFC88</text>
</value>
</field>
<field k='_cd'>
<value>
<text>0:9</text>
</value>
</field>
<field k='_indextime'>
<value>
<text>1524765348</text>
</value>
</field>
<field k='_raw'>
<v xml:space='preserve' trunc='0'>ヒロザキ野村,この世界の戦い:環境が変わって一緒になにかをした方がいいです</v>
</field>
<field k='_serial'>
<value>
<text>2</text>
</value>
</field>
<field k='_si'>
<value>
<text>lknecht-mbpr15</text>
</value>
<value>
<text>test_index</text>
</value>
</field>
<field k='_sourcetype'>
<value>
<text>csv</text>
</value>
</field>
<field k='_time'>
<value>
<text>2018-04-26T10:55:48.000-07:00</text>
</value>
</field>
<field k='host'>
<value>
<text>lknecht-mbpr15</text>
</value>
</field>
<field k='index'>
<value>
<text>test_index</text>
</value>
</field>
<field k='linecount'>
<value>
<text>1</text>
</value>
</field>
<field k='source'>
<value>
<text>日本語.csv</text>
</value>
</field>
<field k='sourcetype'>
<value>
<text>csv</text>
</value>
</field>
<field k='splunk_server'>
<value>
<text>lknecht-mbpr15</text>
</value>
</field>
</result>
<result offset='3'>
<field k='_bkt'>
<value>
<text>test_index~0~5C062B0F-3DA5-41C5-9F21-D15A627EFC88</text>
</value>
</field>
<field k='_cd'>
<value>
<text>0:5</text>
</value>
</field>
<field k='_indextime'>
<value>
<text>1524695954</text>
</value>
</field>
<field k='_raw'>
<v xml:space='preserve' trunc='0'>dunning krugger,TELEF�NICA</v>
</field>
<field k='_serial'>
<value>
<text>3</text>
</value>
</field>
<field k='_si'>
<value>
<text>lknecht-mbpr15</text>
</value>
<value>
<text>test_index</text>
</value>
</field>
<field k='_sourcetype'>
<value>
<text>csv</text>
</value>
</field>
<field k='_time'>
<value>
<text>2018-04-25T15:39:14.000-07:00</text>
</value>
</field>
<field k='host'>
<value>
<text>lknecht-mbpr15</text>
</value>
</field>
<field k='index'>
<value>
<text>test_index</text>
</value>
</field>
<field k='linecount'>
<value>
<text>1</text>
</value>
</field>
<field k='source'>
<value>
<text>test.csv</text>
</value>
</field>
<field k='sourcetype'>
<value>
<text>csv</text>
</value>
</field>
<field k='splunk_server'>
<value>
<text>lknecht-mbpr15</text>
</value>
</field>
</result>
</results>
Conclusion
The "test.csv" file contains the unicode character listed in the GitHub issue #170, and does not have an issue being searched on using the SDK.
The "日本語.csv" file contains Hiragana, Katakana, and Kanji characters, all of which are stored in unicode formats. This did not have an issue with the SDK.
This issue cannot be reproduced and is being suggested as closed as "cannot reproduce".
Suggested Solution
Please upgrade your Python SDK library to version 1.6.3
Closed as "cannot reproduce".