Skip to content

fix(ext): write Jupyter HTML output as UTF-8 - #7999

Open
Diwakar Ray Yadav (Diwak4r) wants to merge 2 commits into
microsoft:mainfrom
Diwak4r:fix/jupyter-html-utf8-encoding
Open

fix(ext): write Jupyter HTML output as UTF-8#7999
Diwakar Ray Yadav (Diwak4r) wants to merge 2 commits into
microsoft:mainfrom
Diwak4r:fix/jupyter-html-utf8-encoding

Conversation

@Diwak4r

Copy link
Copy Markdown

Problem

The _save_html methods in both Jupyter code executors write HTML cell output using Python's platform-default text encoding:

  • autogen_ext/code_executors/jupyter/_jupyter_code_executor.pypath.write_text(html_data)
  • autogen_ext/code_executors/docker_jupyter/_docker_jupyter.pyopen(path, "w")

On Windows the default encoding is the locale codepage (typically cp1252), so saving cell output that contains non-ASCII characters — pandas DataFrame HTML, matplotlib labels, emojis, or any non-Latin text — raises UnicodeEncodeError and aborts execution. On POSIX systems with a non-UTF-8 locale the same failure can occur.

Fix

Pass encoding="utf-8" explicitly on both write paths. HTML is conventionally UTF-8, and this matches the existing convention in the sibling executors (local and docker both already use encoding="utf-8" when writing code files).

How verified

  • Confirmed both call sites previously omitted an encoding argument and would fall back to locale.getpreferredencoding().
  • Reproduced the class of failure: writing HTML containing non-ASCII with the cp1252 default raises UnicodeEncodeError; with encoding="utf-8" it succeeds.
  • Syntax-checked both modified files. Two-line diff, no behavior change on systems already defaulting to UTF-8.

The _save_html methods in the Jupyter and Docker Jupyter code executors
wrote HTML output using the platform default encoding. On Windows this is
cp1252, so saving cell output containing non-ASCII characters (pandas
tables, matplotlib labels, emojis, etc.) raised UnicodeEncodeError. HTML
is conventionally UTF-8, matching the other executors in this package.
Specify encoding="utf-8" explicitly on both write paths.
Copilot AI review requested due to automatic review settings July 26, 2026 11:45

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

Validates that JupyterCodeExecutor writes HTML with non-ASCII characters
(CJK, emoji, accented Latin) using UTF-8 encoding. Regression for microsoftGH-7999
where platform-default encoding caused UnicodeEncodeError on Windows.
@Diwak4r

Copy link
Copy Markdown
Author

Hi team! This fix (UTF-8 Jupyter HTML output) is up to date with main and the fork CI checks that ran are green. A maintainer trigger for the full CI would be appreciated, along with a review when 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.

2 participants