From fbf11ca002c72e55f7a861df415a1e6d1a6a3cf4 Mon Sep 17 00:00:00 2001 From: Florian Agbuya Date: Mon, 29 Jul 2024 18:05:11 +0800 Subject: [PATCH] afws_client: fix unicode error in json handling --- artiq/frontend/afws_client.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/artiq/frontend/afws_client.py b/artiq/frontend/afws_client.py index 020089eaa..fbbbca1a9 100755 --- a/artiq/frontend/afws_client.py +++ b/artiq/frontend/afws_client.py @@ -164,8 +164,8 @@ class Client: if reply[0] != "OK": return reply[0], None length = int(reply[1]) - json_str = (await self.reader.read(length)).decode("ascii") - return "OK", json_str + json_bytes = await self.reader.read(length) + return "OK", json_bytes def get_argparser(): @@ -266,7 +266,7 @@ async def main_async(): variant = args.variant else: variant = await client.get_single_variant(error_msg="User can get JSON of more than 1 variant - need to specify") - result, json_str = await client.get_json(variant) + result, json_bytes = await client.get_json(variant) if result != "OK": if result == "UNAUTHORIZED": print(f"You are not authorized to get JSON of variant {variant}. Your firmware subscription may have expired. Contact helpdesk\x40m-labs.hk.") @@ -275,10 +275,10 @@ async def main_async(): if not args.force and os.path.exists(args.out): print(f"File {args.out} already exists. You can use -f to overwrite the existing file.") sys.exit(1) - with open(args.out, "w") as f: - f.write(json_str) + with open(args.out, "wb") as f: + f.write(json_bytes) else: - print(json_str) + sys.stdout.buffer.write(json_bytes) else: raise ValueError finally: