Unicode Error reading binary files on Arduino GIGA #11408
-
Hi, I'm trying to read non-text files using the default open mode: fin = open('file.png')
content = fin.read()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
UnicodeError: I know that I should open it in binary mode, but actually this happens only on my Arduino Giga R1 (STM32H747) with ARDUINO_GIGA-20230426-v1.20.0.dfu firmware (latest release). I did try: fin = open('file.png', mode='rb')
content = fin.read() # the read works now
fin.close()
content.decode()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
UnicodeError: Also tried decode parameter like: 'ascii','utf-8','unicode'; with same result 'b\'\\x89PNG\\r\\n\\x1a\\n\\x00\\x00\\x00\\rIHDR\\x00\\x00 ... If I try to get it char by char: chr(content(i)) it returns this values: '\x89','P','N','G', ... which encoding is not recognized by the browser, resulting in a broken image. Is there a way to get a byte string as string on the GIGA R1? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment 4 replies
-
Older versions of MicroPython did not always check strings for unicode errors, so that could be the difference. Since you say you know the data is not a string, why are you trying to turn in into a string by calling decode? |
Beta Was this translation helpful? Give feedback.
You can't pass a bytes object for the http response instead of a str?