UnicodeError with os.listdir using nightly builds #10538
-
On an Rpi PIco, I used the uf2 v1.19.1 (2022-06-18) However, I want to use machine.lightsleep. So I start to use the nightly build eg. [v1.19.1-831]. The machine.lightsleep works nicely. However, a get an UnicodeError using: print(os.listdir('/SD/MUZIEK/KLASSIEK/2')) The files in this dir containts some special characters eg.: André Rieu Boléro.mp3 With uf2 v1.19.1 (2022-06-18), there the special characters are handled and no UnicodeErrors occur. What would be your advise, thanks |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
I'm guessing that when the file was created, a character encoding other than UTF-8 was used for the file name. MicroPython now checks that all strings are valid UTF-8. So if there is a way you can rename the file using UTF-8, that should fix the problem. |
Beta Was this translation helpful? Give feedback.
-
I am running into this problem in RPI_PICO_W-20241007-v1.24.0-preview.385.g338df1ae3.uf2. All filenames should be UTF-8, however, the device had a power failure (what appears to be while writing to the card) and now has invalid, inaccessible files on the SD card. It looks like this was fixed in C-Python back in ~ 2009: "by the way of special escaping for undecodable characters (that is, python/cpython#47105 (comment) Would it be possible to take a similar approach, perhaps replacing them with U+FFFD, the Unicode Replacement Character that should be used in situations such as this? |
Beta Was this translation helpful? Give feedback.
I'm guessing that when the file was created, a character encoding other than UTF-8 was used for the file name. MicroPython now checks that all strings are valid UTF-8. So if there is a way you can rename the file using UTF-8, that should fix the problem.