fix: add explicit encoding='utf-8' to open() calls in source packages - #7453
Closed
Krishna Chaitanya (Krishnachaitanyakc) wants to merge 1 commit into
Closed
Krishna Chaitanya (Krishnachaitanyakc) wants to merge 1 commit into
Krishna Chaitanya (Krishnachaitanyakc) wants to merge 1 commit into
Conversation
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.
Author
@microsoft-github-policy-service agree |
Krishna Chaitanya (Krishnachaitanyakc)
marked this pull request as ready for review
March 24, 2026 22:47
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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 causesUnicodeDecodeErrorwhen 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 remainingopen()calls in text mode that lack an explicitencoding='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 writingexperimental/task_centric_memory/utils/chat_completion_client_recorder.py— JSON session read/writeexperimental/task_centric_memory/utils/page_logger.py— HTML log and hash file writingautogen-studio (5 files, 11 call sites):
cli.py— env file writingdatabase/schema_manager.py— Alembic config/template/env.py read/writegallery/builder.py— gallery JSON writinglite/studio.py— env file writingweb/auth/manager.py— YAML config readingmagentic-one-cli (1 file, 2 call sites):
_m1.py— YAML config file readingTest plan
py_compilesyntax verificationopen()calls withoutencodingin text mode across all source directories using AST analysisChecks