Skip to content

fix(io): force UTF-8 for write_json/read_json file I/O#5671

Open
Solaris-star wants to merge 1 commit into
plotly:mainfrom
Solaris-star:fix-io-json-utf8-5665
Open

fix(io): force UTF-8 for write_json/read_json file I/O#5671
Solaris-star wants to merge 1 commit into
plotly:mainfrom
Solaris-star:fix-io-json-utf8-5665

Conversation

@Solaris-star

Copy link
Copy Markdown

Description

pio.write_json / pio.read_json use Path.write_text / Path.read_text without an encoding. On Windows the default is often cp1252, so non-ASCII figure text (e.g. μ 中文) raises UnicodeEncodeError on write or mangles/fails on read. macOS/Linux work only because their default is already UTF-8.

Fix

Always pass encoding="utf-8" for both write and read path I/O.

Test

pytest tests/test_io/test_to_from_json.py::test_write_read_json_utf8_non_ascii -q

Linked Issue

Closes #5665

Path.write_text/read_text without encoding use the locale default, which
on Windows is often cp1252 and raises UnicodeEncodeError/UnicodeDecodeError
for non-ASCII figure text.

Always pass encoding="utf-8" so JSON round-trips match Linux/macOS.

Fixes plotly#5665

Signed-off-by: Solaris-star <820622658@qq.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[BUG]: write_json / read_json raise UnicodeEncodeError on Windows for non-cp1252 characters

1 participant