Skip to content

fix: add explicit encoding='utf-8' to open() calls in source packages - #7453

Closed
Krishna Chaitanya (Krishnachaitanyakc) wants to merge 1 commit into
microsoft:mainfrom
Krishnachaitanyakc:fix/add-utf8-encoding-to-open-calls
Closed

Krishna Chaitanya (Krishnachaitanyakc) wants to merge 1 commit into
microsoft:mainfrom
Krishnachaitanyakc:fix/add-utf8-encoding-to-open-calls

Conversation

@Krishnachaitanyakc

Copy link
Copy Markdown

Summary

Fixes #5566

On non-English Windows systems (e.g., Traditional Chinese with cp950, Japanese with cp932), Python's open() defaults to the system encoding rather than UTF-8. This causes UnicodeDecodeError when reading or writing files that contain non-ASCII characters, such as UTF-8 encoded JavaScript, HTML, JSON, or YAML.

The original issue reported this crash in playwright_controller.py (which has since been fixed), but noted that similar problems exist elsewhere in the codebase. This PR addresses all remaining open() calls in text mode that lack an explicit encoding='utf-8' parameter across the main source directories.

Changes

  • autogen-ext (3 files, 6 call sites):

    • code_executors/docker_jupyter/_docker_jupyter.py — HTML output file writing
    • experimental/task_centric_memory/utils/chat_completion_client_recorder.py — JSON session read/write
    • experimental/task_centric_memory/utils/page_logger.py — HTML log and hash file writing
  • autogen-studio (5 files, 11 call sites):

    • cli.py — env file writing
    • database/schema_manager.py — Alembic config/template/env.py read/write
    • gallery/builder.py — gallery JSON writing
    • lite/studio.py — env file writing
    • web/auth/manager.py — YAML config reading
  • magentic-one-cli (1 file, 2 call sites):

    • _m1.py — YAML config file reading

Test plan

  • All modified files pass py_compile syntax verification
  • Verified zero remaining open() calls without encoding in text mode across all source directories using AST analysis
  • Existing CI tests should pass — this is a safe, additive change that only affects encoding on non-English Windows systems

Checks

On non-English Windows systems, Python's open() uses the system default
encoding (e.g., cp950 for Traditional Chinese, cp932 for Japanese),
which causes UnicodeDecodeError when reading/writing files containing
non-ASCII characters such as UTF-8 encoded JavaScript or HTML.

This adds encoding='utf-8' to all text-mode open() calls in the main
source directories of autogen-ext, autogen-studio, and magentic-one-cli.
@Krishnachaitanyakc

Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

@microsoft-github-policy-service agree

@Krishnachaitanyakc
Krishna Chaitanya (Krishnachaitanyakc) marked this pull request as ready for review March 24, 2026 22:47
@Krishnachaitanyakc

Copy link
Copy Markdown
Author

Closing this PR as there are multiple existing PRs addressing this issue (#5818, #7142, #7194, #7198, #7238, #7257, #7366). Apologies for the duplicate.

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.

open needs encoding='utf-8' for non-english environment, error in playwright_controller.py

1 participant