forked from M-Labs/artiq
afws_client: fix unicode error in json handling
Signed-off-by: Florian Agbuya <fa@m-labs.ph>
This commit is contained in:
parent
61986e4f2b
commit
13250427e0
@ -158,8 +158,8 @@ class Client:
|
|||||||
if reply[0] != "OK":
|
if reply[0] != "OK":
|
||||||
return reply[0], None
|
return reply[0], None
|
||||||
length = int(reply[1])
|
length = int(reply[1])
|
||||||
json_str = self.fsocket.read(length).decode("ascii")
|
json_bytes = self.fsocket.read(length)
|
||||||
return "OK", json_str
|
return "OK", json_bytes
|
||||||
|
|
||||||
|
|
||||||
def get_argparser():
|
def get_argparser():
|
||||||
@ -259,7 +259,7 @@ def main():
|
|||||||
variant = args.variant
|
variant = args.variant
|
||||||
else:
|
else:
|
||||||
variant = client.get_single_variant(error_msg="User can get JSON of more than 1 variant - need to specify")
|
variant = client.get_single_variant(error_msg="User can get JSON of more than 1 variant - need to specify")
|
||||||
result, json_str = client.get_json(variant)
|
result, json_bytes = client.get_json(variant)
|
||||||
if result != "OK":
|
if result != "OK":
|
||||||
if result == "UNAUTHORIZED":
|
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.")
|
print(f"You are not authorized to get JSON of variant {variant}. Your firmware subscription may have expired. Contact helpdesk\x40m-labs.hk.")
|
||||||
@ -268,10 +268,10 @@ def main():
|
|||||||
if not args.force and os.path.exists(args.out):
|
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.")
|
print(f"File {args.out} already exists. You can use -f to overwrite the existing file.")
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
with open(args.out, "w") as f:
|
with open(args.out, "wb") as f:
|
||||||
f.write(json_str)
|
f.write(json_bytes)
|
||||||
else:
|
else:
|
||||||
print(json_str)
|
sys.stdout.buffer.write(json_bytes)
|
||||||
else:
|
else:
|
||||||
raise ValueError
|
raise ValueError
|
||||||
finally:
|
finally:
|
||||||
|
Loading…
Reference in New Issue
Block a user