Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

azhengzz
Copy link
Contributor

@azhengzz azhengzz commented Aug 28, 2025

fix codec error while writing log, below is the detailed error message

--- Logging error ---
Traceback (most recent call last):
  File "D:\IDE\Python\Python312\Lib\logging\__init__.py", line 1163, in emit
    stream.write(msg + self.terminator)
UnicodeEncodeError: 'gbk' codec can't encode character '\U0001f4be' in position 63: illegal multibyte sequence
Call stack:
  File "D:\WorkHome\git\gitee\azhengzz\browser-use\example_one.py", line 147, in <module>
    asyncio.run(main())
  File "D:\IDE\Python\Python312\Lib\asyncio\runners.py", line 194, in run
    return runner.run(main)
  File "D:\IDE\Python\Python312\Lib\asyncio\runners.py", line 118, in run
    return self._loop.run_until_complete(task)
  File "D:\IDE\Python\Python312\Lib\asyncio\base_events.py", line 673, in run_until_complete
    self.run_forever()
  File "D:\IDE\Python\Python312\Lib\asyncio\windows_events.py", line 322, in run_forever
    super().run_forever()
  File "D:\IDE\Python\Python312\Lib\asyncio\base_events.py", line 640, in run_forever
    self._run_once()
  File "D:\IDE\Python\Python312\Lib\asyncio\base_events.py", line 1992, in _run_once
    handle._run()
  File "D:\IDE\Python\Python312\Lib\asyncio\events.py", line 88, in _run
    self._context.run(self._callback, *self._args)
  File "D:\WorkHome\git\gitee\azhengzz\browser-use\example_one.py", line 131, in main
    agent = Agent(
  File "D:\WorkHome\git\gitee\azhengzz\browser-use\browser_use\utils.py", line 330, in wrapper
    result = func(*args, **kwargs)
  File "D:\WorkHome\git\gitee\azhengzz\browser-use\browser_use\agent\service.py", line 267, in __init__
    self._set_file_system(file_system_path)
  File "D:\WorkHome\git\gitee\azhengzz\browser-use\browser_use\agent\service.py", line 512, in _set_file_system
    logger.debug(f'💾 File system path: {self.file_system_path}')
Message: '💾 File system path: C:\\Users\\Zheng\\AppData\\Local\\Temp\\browser_use_agent_068aff10-a1d9-7ee5-8000-803a64a9e569_1756360970'
Arguments: ()

Summary by cubic

Force UTF-8 encoding for log file handlers to fix UnicodeEncodeError when writing non-ASCII characters (e.g., emojis) to log files, especially on Windows with GBK locales. Logs now write reliably without crashing.

  • Bug Fixes
    • Set encoding='utf-8' on debug and info FileHandlers to prevent 'gbk' codec errors.

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

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

No issues found across 1 file

@MagMueller MagMueller merged commit 402c040 into browser-use:main Sep 6, 2025
49 checks passed
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