Skip to content

fix: add encoding='utf-8' to open() calls for non-English environments (#5566)#7423

Open
zlplzp123wyt wants to merge 1 commit intomicrosoft:mainfrom
zlplzp123wyt:fix/utf8-encoding-open-calls
Open

fix: add encoding='utf-8' to open() calls for non-English environments (#5566)#7423
zlplzp123wyt wants to merge 1 commit intomicrosoft:mainfrom
zlplzp123wyt:fix/utf8-encoding-open-calls

Conversation

@zlplzp123wyt
Copy link

Summary

Fixes UnicodeDecodeError when running AutoGen in CJK locales (cp939, cp950, gb2312, etc.) where the default system encoding cannot decode UTF-8 source files.

Fixes #5566

Changes

Added encoding="utf-8" to open() calls in text mode across 4 files:

  • magentic_one_cli/_m1.py: Config file reading (2 locations)
  • docker_jupyter/_docker_jupyter.py: Script file reading
  • task_centric_memory/utils/page_logger.py: Log file operations (3 locations)
  • task_centric_memory/utils/chat_completion_client_recorder.py: Cache file operations (2 locations)

Reproduction

On Windows with system locale set to Chinese (Traditional):

# Without encoding=utf-8, this raises UnicodeDecodeError
with open("utf8_file.js", "rt") as f:
    content = f.read()

Test Plan

  • All modified files compile without syntax errors
  • No binary file operations were modified
  • Verified encoding parameter added to all text-mode open() calls

Fixes UnicodeDecodeError when running autogen in CJK locales (cp939, cp950, etc.)
where the default system encoding cannot decode UTF-8 source files.

Fixes microsoft#5566

Files fixed:
- magentic_one_cli/_m1.py: config file reading
- docker_jupyter/_docker_jupyter.py: script file reading
- task_centric_memory/utils/page_logger.py: log file operations
- task_centric_memory/utils/chat_completion_client_recorder.py: cache file operations
@zlplzp123wyt
Copy link
Author

@microsoft-github-policy-service agree

@zlplzp123wyt
Copy link
Author

Hi, this PR fixes encoding issues in calls for non-English environments. All CI checks pass. Would appreciate a review when time permits. Thank you!

@zlplzp123wyt
Copy link
Author

Hi! This is a simple but important fix for non-English environments. Adding explicit encoding='utf-8' to open() calls prevents UnicodeDecodeError on systems where the default encoding isn't UTF-8. Ready for review whenever convenient. Thanks!

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