From 9ef371f619c3fc514c38c83d75930838a3bffb10 Mon Sep 17 00:00:00 2001 From: Abhi Shah Date: Mon, 3 Jul 2023 14:52:55 +0530 Subject: [PATCH 1/2] Update six.py - replaced 'strict' error checking with 'replace' --- splunklib/six.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/splunklib/six.py b/splunklib/six.py index d13e50c9..f926bd8a 100644 --- a/splunklib/six.py +++ b/splunklib/six.py @@ -898,7 +898,7 @@ def ensure_binary(s, encoding='utf-8', errors='strict'): raise TypeError("not expecting type '%s'" % type(s)) -def ensure_str(s, encoding='utf-8', errors='strict'): +def ensure_str(s, encoding='utf-8', errors='replace'): """Coerce *s* to `str`. For Python 2: From d2a4af21c95ae6f8b6c0ab13d63487b3ef33ce06 Mon Sep 17 00:00:00 2001 From: Abhi Shah Date: Tue, 11 Jul 2023 15:46:50 +0530 Subject: [PATCH 2/2] updated errors check for encode/decode --- splunklib/modularinput/event_writer.py | 2 +- splunklib/searchcommands/search_command.py | 2 +- splunklib/six.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/splunklib/modularinput/event_writer.py b/splunklib/modularinput/event_writer.py index 5f8c5aa8..38a110c1 100644 --- a/splunklib/modularinput/event_writer.py +++ b/splunklib/modularinput/event_writer.py @@ -77,7 +77,7 @@ def write_xml_document(self, document): :param document: An ``ElementTree`` object. """ - self._out.write(ensure_str(ET.tostring(document))) + self._out.write(ensure_str(ET.tostring(document), errors="replace")) self._out.flush() def close(self): diff --git a/splunklib/searchcommands/search_command.py b/splunklib/searchcommands/search_command.py index dd11391d..30b1d1c2 100644 --- a/splunklib/searchcommands/search_command.py +++ b/splunklib/searchcommands/search_command.py @@ -934,7 +934,7 @@ def _read_chunk(istream): except Exception as error: raise RuntimeError('Failed to read body of length {}: {}'.format(body_length, error)) - return metadata, six.ensure_str(body) + return metadata, six.ensure_str(body, errors="replace") _header = re.compile(r'chunked\s+1.0\s*,\s*(\d+)\s*,\s*(\d+)\s*\n') diff --git a/splunklib/six.py b/splunklib/six.py index f926bd8a..d13e50c9 100644 --- a/splunklib/six.py +++ b/splunklib/six.py @@ -898,7 +898,7 @@ def ensure_binary(s, encoding='utf-8', errors='strict'): raise TypeError("not expecting type '%s'" % type(s)) -def ensure_str(s, encoding='utf-8', errors='replace'): +def ensure_str(s, encoding='utf-8', errors='strict'): """Coerce *s* to `str`. For Python 2: