From c2bba2541323e8354616731b25231588a36d6ebc Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Tue, 23 Jan 2024 13:09:36 +0800 Subject: [PATCH] scylla_node: encode stdout and stderr if not text if there are no sstables, and we expect bytes as the output, we should encode the encoded json into bytes before returning it. otherwise we'd have exception like: ``` AttributeError: 'str' object has no attribute 'decode'. Did you mean: 'encode'? ``` when trying to decode the returned stdout. Signed-off-by: Kefu Chai --- ccmlib/scylla_node.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/ccmlib/scylla_node.py b/ccmlib/scylla_node.py index 7b2e382f..1d97bdb5 100644 --- a/ccmlib/scylla_node.py +++ b/ccmlib/scylla_node.py @@ -1465,7 +1465,10 @@ def do_invoke(sstables): if not sstables: empty_dump = {'sstables': {'anonymous': []}} stdout, stderr = json.dumps(empty_dump), '' - return (stdout, stderr) + if text: + return stdout, stderr + else: + return stdout.encode('utf-8'), stderr.encode('utf-8') common_args = [scylla_path, "sstable", command] + additional_args env = self._get_environ() res = subprocess.run(common_args + sstables, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=text, check=False, env=env)