autogen icon indicating copy to clipboard operation
autogen copied to clipboard

[Bug]: when used in Windows, the error "UnicodeDecodeError: 'gbk' codec can't decode byte 0xb3 in position 2130: illegal multibyte sequence" occur

Open cipher0416 opened this issue 1 year ago • 10 comments

Describe the bug

When I use to have multiple agents talk, one of them acts as a code executor, executing the python script and returning it. If the returned content contains GBK-encoded characters, an error is reported and the program stops abnormally.

Traceback (most recent call last): File "D:\software\python-3.9.13\lib\threading.py", line 917, in run self._target(*self._args, **self._kwargs) File "D:\software\python-3.9.13\lib\subprocess.py", line 1479, in _readerthread buffer.append(fh.read()) UnicodeDecodeError: 'gbk' codec can't decode byte 0xb3 in position 2130: illegal multibyte sequence Exception in thread Thread-5: Traceback (most recent call last): File "D:\software\python-3.9.13\lib\threading.py", line 980, in _bootstrap_inner self.run() File "D:\software\python-3.9.13\lib\threading.py", line 917, in run self._target(*self._args, **self._kwargs) File "D:\software\python-3.9.13\lib\subprocess.py", line 1479, in _readerthread buffer.append(fh.read()) UnicodeDecodeError: 'gbk' codec can't decode byte 0xb3 in position 2130: illegal multibyte sequence Traceback (most recent call last): File "D:\ADN\projectcode\PythonProject\AutoGen\venv\lib\site-packages\autogen\agentchat\groupchat.py", line 549, in run_chat reply = speaker.generate_reply(sender=self) File "D:\ADN\projectcode\PythonProject\AutoGen\venv\lib\site-packages\autogen\agentchat\conversable_agent.py", line 1646, in generate_reply final, reply = reply_func(self, messages=messages, sender=sender, config=reply_func_tuple["config"]) File "D:\ADN\projectcode\PythonProject\AutoGen\venv\lib\site-packages\autogen\agentchat\conversable_agent.py", line 1206, in generate_code_execution_reply exitcode, logs = self.execute_code_blocks(code_blocks) File "D:\ADN\projectcode\PythonProject\AutoGen\venv\lib\site-packages\autogen\agentchat\conversable_agent.py", line 1830, in execute_code_blocks logs_all += "\n" + logs TypeError: can only concatenate str (not "NoneType") to str

Steps to reproduce

No response

Expected Behavior

No response

Screenshots and logs

No response

Additional Information

I tryed modify the source code in code_utils.py with add encoding, it solved: with ThreadPoolExecutor(max_workers=1) as executor: future = executor.submit( subprocess.run, cmd, cwd=work_dir, capture_output=True, text=True, encoding='utf-8' )

### Tasks

cipher0416 avatar Feb 21 '24 09:02 cipher0416

I got similar issue on my side using autogenstudio 0.0.44a0 . I wrote a skill that fetches some confluence articles, and it failed on some characters that were not unicode, like 0x9d.

bodzebod avatar Feb 21 '24 14:02 bodzebod

@ekzhu It seems like an issue reading txt from non-ASCII/Unicode encoding. GBK encoding is usually designed for older version of Windows machine (for non-English language).

BeibinLi avatar Feb 21 '24 23:02 BeibinLi

I encountered the same error, and I also used the method mentioned in the article to solve it. I am currently using the Chinese version of Windows 11.

suepradun avatar Feb 22 '24 13:02 suepradun

@suepradun what article are you referring to?

bodzebod avatar Feb 22 '24 14:02 bodzebod

image same promblem on windows add the param "encoding" = 'utf-8' in subprocess.run() inside the file "local_commandline_code_executor.py", and it works.

starrywing-v2 avatar Apr 19 '24 07:04 starrywing-v2

why not submit a bug-fix pr? I used autogen as library, therefore I can't modify the source code

SuMiaoALi avatar Aug 23 '24 08:08 SuMiaoALi

I got the same error only when I was using GPT-4o-mini in Windows venv, and none of the above two solution works...

szwang-seedtech avatar Sep 04 '24 09:09 szwang-seedtech