Handle invalid unicode in json response
This commit is contained in:
committed by
Brett Rowan
parent
b2726c77a0
commit
a1a7562bdb
@@ -253,10 +253,10 @@ If you are sure you want to use this command please use API.send_command("{comma
|
|||||||
# some json from the API returns with a null byte (\x00) on the end
|
# some json from the API returns with a null byte (\x00) on the end
|
||||||
if data.endswith(b"\x00"):
|
if data.endswith(b"\x00"):
|
||||||
# handle the null byte
|
# handle the null byte
|
||||||
str_data = data.decode("utf-8")[:-1]
|
str_data = data.decode("utf-8", errors="replace")[:-1]
|
||||||
else:
|
else:
|
||||||
# no null byte
|
# no null byte
|
||||||
str_data = data.decode("utf-8")
|
str_data = data.decode("utf-8", errors="replace")
|
||||||
# fix an error with a btminer return having an extra comma that breaks json.loads()
|
# fix an error with a btminer return having an extra comma that breaks json.loads()
|
||||||
str_data = str_data.replace(",}", "}")
|
str_data = str_data.replace(",}", "}")
|
||||||
# fix an error with a btminer return having a newline that breaks json.loads()
|
# fix an error with a btminer return having a newline that breaks json.loads()
|
||||||
|
|||||||
Reference in New Issue
Block a user