Repository navigation
open needs encoding='utf-8' for non-english environment, error in playwright_controller.py #5566
Copy link
Copy link
Open
Labels
good first issueGood for newcomersGood for newcomershelp wantedExtra attention is neededExtra attention is needed
Milestone
Description
What happened?
C:\Users\Bear\miniconda3\envs\ai2\Lib\site-packages\magentic_one_cli\_m1.py:59: DeprecationWarning: Instantiating MagenticOne without a code_executor is deprecated. Provide a code_executor to clear this warning (e.g., code_executor=LocalCommandLineCodeExecutor() ).
m1 = MagenticOne(client=client, hil_mode=hil_mode, input_func=input_manager.get_wrapped_callback())
Traceback (most recent call last):
File "<frozen runpy>", line 198, in _run_module_as_main
File "<frozen runpy>", line 88, in _run_code
File "C:\Users\Bear\miniconda3\envs\ai2\Scripts\m1.exe\__main__.py", line 7, in <module>
sys.exit(main())
~~~~^^
File "C:\Users\Bear\miniconda3\envs\ai2\Lib\site-packages\magentic_one_cli\_m1.py", line 67, in main
asyncio.run(run_task(task, not args.no_hil, args.rich))
~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\Bear\miniconda3\envs\ai2\Lib\asyncio\runners.py", line 195, in run
return runner.run(main)
~~~~~~~~~~^^^^^^
File "C:\Users\Bear\miniconda3\envs\ai2\Lib\asyncio\runners.py", line 118, in run
return self._loop.run_until_complete(task)
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^
File "C:\Users\Bear\miniconda3\envs\ai2\Lib\asyncio\base_events.py", line 725, in run_until_complete
return future.result()
~~~~~~~~~~~~~^^
File "C:\Users\Bear\miniconda3\envs\ai2\Lib\site-packages\magentic_one_cli\_m1.py", line 59, in run_task
m1 = MagenticOne(client=client, hil_mode=hil_mode, input_func=input_manager.get_wrapped_callback())
File "C:\Users\Bear\miniconda3\envs\ai2\Lib\site-packages\autogen_ext\teams\magentic_one.py", line 144, in __init__
ws = MultimodalWebSurfer("WebSurfer", model_client=client)
File "C:\Users\Bear\miniconda3\envs\ai2\Lib\site-packages\autogen_ext\agents\web_surfer\_multimodal_web_surfer.py", line 268, in __init__
self._playwright_controller = PlaywrightController(
~~~~~~~~~~~~~~~~~~~~^
animate_actions=self.animate_actions,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
...<4 lines>...
to_resize_viewport=self.to_resize_viewport,
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
)
^
File "C:\Users\Bear\miniconda3\envs\ai2\Lib\site-packages\autogen_ext\agents\web_surfer\playwright_controller.py", line 68, in __init__
self._page_script = fh.read()
~~~~~~~^^
UnicodeDecodeError: 'cp950' codec can't decode byte 0xe2 in position 11569: illegal multibyte sequence
simply add encoding='utf-8' in line 67:
with open(os.path.join(os.path.abspath(os.path.dirname(__file__)), "page_script.js"), "rt", encoding='utf-8') as fh:
can solve the issue, and i think there will be some similar issues in code base while using open function.
What did you expect to happen?
No error
How can we reproduce it (as minimally and precisely as possible)?
m1 --rich "我手上有一些尚未投入到投市的資金, 預計投入到 VT 和 SOXX, 請問現在是好的時機點嗎? 或是我應該再等一陣子低點入市? 我打算是長期投資, 但依然希望不要有過高的持有成本以免影響我的績效, 而且因為我現在要分批投入的是主要資金, 所以就算之後定期定額, 現在的買點也是很重要"
AutoGen version
0.4.7
Which package was this bug in
Magentic One
Model used
No response
Python version
No response
Operating system
No response
Any additional info you think would be helpful for fixing this bug
No response
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
good first issueGood for newcomersGood for newcomershelp wantedExtra attention is neededExtra attention is needed
Activity
ekzhu commentedon Feb 19, 2025
Seem like a easy fix, could you submit a PR for this?
sepehr-rs commentedon Mar 1, 2025
Hi, I’d like to take this issue and submit a fix. It looks like a straightforward and trivial change, but I’ll follow the contribution guidelines to ensure everything is in order. Let me know if there are any additional considerations.
ekzhu commentedon Mar 1, 2025
Thanks please go ahead
bear0330 commentedon Mar 4, 2025
Sorry for late to give a response. In the beginning, I wanted to submit a PR, but I tried to use a regular expression to fix all open without encoding='utf-8' not only the line of issue I mentioned. This seems need some thinking and test, so I late.
I am happy that @sepehrrasooli wants to take care this. Thank you. 👍
sepehr-rs commentedon Mar 4, 2025
Thanks! I'll take care of this and submit a PR soon. Let me know if there's anything specific you'd like me to consider
fix: add explicit UTF-8 encoding to file operations
paipeline commentedon Feb 14, 2026
This issue has been resolved in commit 9a05883 via PR #6094 "add utf encoding in websurfer read file".
The problematic line now correctly includes
encoding='utf-8':This issue can be closed as the fix is already in main branch.
Fix encoding issues in file reading operations
fix: add encoding='utf-8' to open() calls in autogen-ext
32 remaining items
harishn1408 commentedon May 6, 2026
🤖 Autonomous Solution Proposal
I have analyzed this issue and generated a production-ready fix:
Solution to GitHub Issue #5566: UnicodeDecodeError in playwright_controller.py
Problem Statement:
The issue arises when the
openfunction is used without specifying the encoding, leading to a UnicodeDecodeError in theplaywright_controller.pyfile.Solution:
To fix this issue, we need to specify the encoding when opening the file. We can do this by adding the
encoding='utf-8'parameter to theopenfunction.Modified Code:
Additional Recommendations:
openfunctions: To avoid similar issues in the codebase, we should specify the encoding for allopenfunctions. We can use a consistent encoding, such asutf-8, for all files.withstatement: Thewithstatement is used to ensure that the file is properly closed after it is no longer needed. This is a good practice to follow.errorsparameter of theopenfunction to specify how to handle encoding errors. For example, we can useerrors='ignore'to ignore encoding errors.Example Code:
Commit Message:
API Documentation:
Generated by Sovereign-Automaton.
fix: add encoding='utf-8' to open() calls for non-English environments
fix: add explicit encoding='utf-8' to all text file operations
fix: add explicit encoding='utf-8' to all text file operations
nexoracontrol-ops commentedon May 8, 2026
fix: add encoding='utf-8' to remaining open() calls in source code
hsms4710-pixel commentedon Jun 24, 2026
Hi Bear Huang (@bear0330), thanks for reporting this issue! 👋
I was looking into this and found that
encoding="utf-8"has already been added toplaywright_controller.pyat line 67 in the latestmainbranch:🔗 View on GitHub
This fix should be included in versions after v0.4.7.
Could you please:
Thanks for helping improve AutoGen! 🚀
test: add UTF-8 encoding regression tests (microsoft#5566)
hsms4710-pixel commentedon Jun 25, 2026
Hi! I've submitted a PR (#7880) to add UTF-8 encoding regression tests. Please review when you have time. Thank you!
IgorGanapolsky commentedon Jul 24, 2026
Agentic systems are turning into always-on factories: one request fans out into model calls, tool calls, policy checks, and storage.
The hard part is rarely tokens/sec — it is control-plane reliability:
If you share one sanitized failing run (expected vs actual + tool result), I can map which pillar is broken. Architecture only.
wooyongbin3-cpu commentedon Aug 15, 2026
This issue has already been fixed in the current main branch. The �ncoding='utf-8' parameter is already present in playwright_controller.py line 72.
See: https://github.com/microsoft/autogen/blob/main/python/packages/autogen-ext/src/autogen_ext/agents/web_surfer/playwright_controller.py#L72
Closing as already fixed.
wooyongbin3-cpu commentedon Aug 15, 2026
Already fixed in main - encoding='utf-8' is already present in playwright_controller.py
mukktinaadh commentedon Aug 30, 2026
The fix for this issue was already merged in commit 9a05883 (PR #6094) on 2025-03-25. The fix adds
encoding="utf-8"to the file read operation inplaywright_controller.py. The current main branch already has this fix:This fix was merged in PR #6094 on 2025-03-25. The issue can be closed as the fix is already in main branch.
VimalN2005 commentedon Sep 12, 2026
Hi Open Source Maintainers on GitHub [moved] (@maintainers),
I investigated this issue and verified that multiple file I/O calls across
autogen-ext,autogen-studio, andmagentic-one-cliomit explicitencoding="utf-8"when reading or writing text files (.html,.json,.yaml,.ini). On Windows and non-English locales (e.g. CP1252, CP950), this triggersUnicodeDecodeError/UnicodeEncodeError.I have already implemented the fix across the affected packages in accordance with PEP 597 and verified all tests pass locally.
Could you please assign this issue to me? I can submit the Pull Request right away.
fix(python): standardizing open() calls with explicit encoding='utf-8…