fix(ext): write Jupyter HTML output as UTF-8 - #7999
Open
Diwakar Ray Yadav (Diwak4r) wants to merge 2 commits into
Open
fix(ext): write Jupyter HTML output as UTF-8#7999Diwakar Ray Yadav (Diwak4r) wants to merge 2 commits into
Diwakar Ray Yadav (Diwak4r) wants to merge 2 commits into
Conversation
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.
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.
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! |
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.
Problem
The
_save_htmlmethods in both Jupyter code executors write HTML cell output using Python's platform-default text encoding:autogen_ext/code_executors/jupyter/_jupyter_code_executor.py—path.write_text(html_data)autogen_ext/code_executors/docker_jupyter/_docker_jupyter.py—open(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
UnicodeEncodeErrorand 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 (localanddockerboth already useencoding="utf-8"when writing code files).How verified
locale.getpreferredencoding().UnicodeEncodeError; withencoding="utf-8"it succeeds.