mirror of
https://github.com/micropython/micropython.git
synced 2025-12-16 09:50:15 +01:00
tools/mpremote: Fix encoding error in PyboardCommand.
This is a fix for utf-8 decoding errors that are thrown when non-utf-8 content is received. For instance during a reboot of an ESP8266 module. The fix is to handle conversion errors by replacing illegal characters. Note that these illegal characters most often occur during an MCU reboot sequence when the MCU is using baudrates different from 115200. Signed-off-by: Jos Verlinde <Jos_Verlinde@hotmail.com>
This commit is contained in:
committed by
Damien George
parent
8c47ff7153
commit
20e1ae0733
@@ -795,7 +795,7 @@ class PyboardCommand:
|
||||
if n == 0:
|
||||
return ""
|
||||
else:
|
||||
return str(self.fin.read(n), "utf8")
|
||||
return str(self.fin.read(n), "utf8", errors="backslashreplace")
|
||||
|
||||
def wr_s8(self, i):
|
||||
self.fout.write(struct.pack("<b", i))
|
||||
@@ -925,7 +925,7 @@ class PyboardCommand:
|
||||
fd = self.rd_s8()
|
||||
buf = self.rd_bytes()
|
||||
if self.data_files[fd][1]:
|
||||
buf = str(buf, "utf8")
|
||||
buf = str(buf, "utf8", errors="backslashreplace")
|
||||
n = self.data_files[fd][0].write(buf)
|
||||
self.wr_s32(n)
|
||||
# self.log_cmd(f"write {fd} {len(buf)} -> {n}")
|
||||
|
||||
Reference in New Issue
Block a user