Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

open needs encoding='utf-8' for non-english environment, error in playwright_controller.py #5566

Open
bear0330 opened this issue Feb 16, 2025 · 5 comments · May be fixed by #5818
Open

open needs encoding='utf-8' for non-english environment, error in playwright_controller.py #5566

bear0330 opened this issue Feb 16, 2025 · 5 comments · May be fixed by #5818
Assignees
Labels
good first issue Good for newcomers help wanted Extra attention is needed
Milestone

Comments

@bear0330
Copy link

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

@ekzhu
Copy link
Collaborator

ekzhu commented Feb 19, 2025

Seem like a easy fix, could you submit a PR for this?

@ekzhu ekzhu added good first issue Good for newcomers help wanted Extra attention is needed labels Feb 19, 2025
@ekzhu ekzhu added this to the 0.4.x-python milestone Feb 19, 2025
@sepehrrasooli
Copy link

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
Copy link
Collaborator

ekzhu commented Mar 1, 2025

Thanks please go ahead

@bear0330
Copy link
Author

bear0330 commented 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. 👍

@sepehrrasooli
Copy link

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. 👍

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

@sepehrrasooli sepehrrasooli linked a pull request Mar 4, 2025 that will close this issue
3 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants