hikctl crashes with UnicodeEncodeError on cp1252 stdout after completing the action #181

Open
opened 2026-09-28 13:40:30 +00:00 by gabogg · 0 comments
Owner

Problem

Over non-interactive SSH, or whenever stdout is redirected, Python on Windows falls back to the cp1252 console encoding. The hikctl console helpers print characters outside cp1252 (✓, ✗, box-drawing ╔═╗) in app/cli/common/console.py (header, success, error). As a result, every command crashes with UnicodeEncodeError: 'charmap' codec can't encode character '✓'.

The crash comes after the action has already run. On 2026-09-28, user add visualData --role viewer --password ... created the user and wrote USER_CREATE to lifecycle.log, then printed three chained tracebacks. An operator would reasonably think the command failed and retry it. user list fails outright.

hikctl.cmd doesn't set an encoding either, so it is affected the same way.

Expected

CLI output never raises because of the terminal encoding. Two possible fixes: call sys.stdout.reconfigure(errors="replace") or switch to UTF-8 at CLI entry, or have the console fall back to ASCII glyphs ([OK], [X], +--+). Setting PYTHONIOENCODING=utf-8 works around it for now.

## Problem Over non-interactive SSH, or whenever stdout is redirected, Python on Windows falls back to the `cp1252` console encoding. The `hikctl` console helpers print characters outside cp1252 (`✓`, `✗`, box-drawing `╔═╗`) in `app/cli/common/console.py` (`header`, `success`, `error`). As a result, every command crashes with `UnicodeEncodeError: 'charmap' codec can't encode character '✓'`. The crash comes **after** the action has already run. On 2026-09-28, `user add visualData --role viewer --password ...` created the user and wrote `USER_CREATE` to `lifecycle.log`, then printed three chained tracebacks. An operator would reasonably think the command failed and retry it. `user list` fails outright. `hikctl.cmd` doesn't set an encoding either, so it is affected the same way. ## Expected CLI output never raises because of the terminal encoding. Two possible fixes: call `sys.stdout.reconfigure(errors="replace")` or switch to UTF-8 at CLI entry, or have the console fall back to ASCII glyphs (`[OK]`, `[X]`, `+--+`). Setting `PYTHONIOENCODING=utf-8` works around it for now.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set

Reference
gabogg/hikcentral#181
No description provided.