← index #18656Issue #18643
Related · high · value 3.867
QUERY · ISSUE

mpremote fails with UnicodeEncodeError on Windows legacy consoles (cp1252)

openby Josverlopened 2026-01-07updated 2026-01-09
bugtoolsunicode

Port, board and/or hardware

Windows (any hardware) - affects mpremote tool when run on Windows with legacy console (cp1252 or similar encoding).

MicroPython version

  • mpremote 1.27.0
  • Python 3.11.9 /3.13.1 (host)
  • Tested against MicroPython 1.27.0 RP2, ESP32

Reproduction

This issue only occurs with legacy Windows consoles that use cp1252 or similar encodings. Modern terminals (Windows Terminal, VS Code) use UTF-8 by default and are not affected.

To reproduce, you must use a legacy console:

  1. Open legacy cmd.exe (not Windows Terminal) or configure PowerShell to use cp1252:

    # Force legacy encoding in Python
    $env:PYTHONIOENCODING = "cp1252"
    
  2. Create test files with non-ASCII characters:

    mkdir unicode_test
    echo "test" > "unicode_test\Владимир_Петров.txt"
    
  3. Use mpremote to copy:

    mpremote cp -rv unicode_test :
    

Alternatively, the issue can be demonstrated with this Python snippet:

import sys
sys.stdout.reconfigure(encoding='cp1252')
print('Владимир_Петров.txt')  # Raises UnicodeEncodeError

Expected behaviour

mpremote cp should successfully copy files with Unicode characters in filenames on Windows. The tool should handle all Unicode characters in console output without raising encoding errors.

CPython's print() should use UTF-8 or properly handle the console encoding.

Observed behaviour

The command fails immediately with:

UnicodeEncodeError: 'charmap' codec can't encode characters in position X-Y: character maps to <undefined>

The file is not copied.

Additional Information

Workaround

Set the PYTHONIOENCODING environment variable before running mpremote:

$env:PYTHONIOENCODING = "utf-8"
mpremote connect COM3 cp -r . :

Or add to PowerShell $PROFILE for persistence:

$env:PYTHONIOENCODING = "utf-8"
$env:PYTHONUTF8 = "1"

Suggested Fix

Force UTF-8 encoding in mpremote on Windows:

import sys
import io

if sys.platform == 'win32':
    sys.stdout = io.TextIOWrapper(sys.stdout.buffer, encoding='utf-8', errors='replace')
    sys.stderr = io.TextIOWrapper(sys.stderr.buffer, encoding='utf-8', errors='replace')

This would be a minimal change in the mpremote initialization code.

Code of Conduct

Yes, I agree

CANDIDATE · ISSUE

mpremote gives UnicodeError on ARDUINO_OPTA V26, V27, V28

openby tb4450opened 2026-01-05updated 2026-01-20
bugport-stm32

Port, board and/or hardware

ARDUINO_OPTA

MicroPython version

MicroPython v1.26.1 on 2025-09-11; Arduino OPTA with STM32H747

I do not have the WIFI version but the simplest without WIFI and RS485. Might this be the problem?

The same on V27 (latest) and V28 (preview).

py.exe -m mpremote connect COM9 fs tree
tree :
:/flash
mpremote: Error with transport:
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
UnicodeError:

It's not possible to upload any file or use any filesystem function of mpremote.

mpremote repl works!

Using mpremote 1.27.0 on Windows with Python 3.14.2.

Thank you
Best greetings
Thomas

Reproduction

Connect OPTA and run mpremote.

py.exe -m mpremote connect COM9 fs tree
tree :
:/flash
mpremote: Error with transport:
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
UnicodeError:

Expected behaviour

The command should give a similar output to the following;

py.exe -m mpremote connect COM10 fs tree
tree :
:/flash
├── BOOTEX.LOG
├── FOUND.000
│ ├── FILE0000.CHK
│ ├── FILE0001.CHK
│ ├── FILE0002.CHK
│ ├── FILE0003.CHK
│ └── FILE0004.CHK
├── README.txt
├── System Volume Information
│ ├── IndexerVolumeGuid
│ └── WPSettings.dat
├── _mqtt_test_pybd.txt
├── boot.py

Observed behaviour

mpremote ends with the error message "UnicodeError":

py.exe -m mpremote connect COM9 fs tree
tree :
:/flash
mpremote: Error with transport:
Traceback (most recent call last):
File "<stdin>", line 2, in <module>
UnicodeError:

Additional Information

No, I've provided everything above.

Code of Conduct

Yes, I agree

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied