Skip to content

Windows读取命令,GBK和UTF-8编码冲突报错 #241

@Muprprpr

Description

@Muprprpr

System Info / 系統信息

python=3.12
Windows 11

Who can help? / 谁可以帮助到您?

No response

Information / 问题信息

  • The official example scripts / 官方的示例脚本
  • My own modified scripts / 我自己修改的脚本和任务

Reproduction / 复现过程

python main.py --base-url https://open.bigmodel.cn/api/paas/v4 --model "autoglm-phone" --apikey "*******" "打开微信,向我的微信好友‘***’发起视频聊天,同时请使用前置摄像头"
🔍 Checking system requirements...
--------------------------------------------------
1. Checking ADB installation... ✅ OK (Android Debug Bridge version 1.0.41)
2. Checking connected devices... ✅ OK (1 device(s): 3AG9K24724000705)
3. Checking ADB Keyboard... ✅ OK
--------------------------------------------------
✅ All system checks passed!

🔍 Checking model API...
--------------------------------------------------
1. Checking API connectivity (https://open.bigmodel.cn/api/paas/v4)... ✅ OK
--------------------------------------------------
✅ Model API checks passed!

==================================================
Phone Agent - AI-powered phone automation
==================================================
Model: autoglm-phone
Base URL: https://open.bigmodel.cn/api/paas/v4
Max Steps: 100
Language: cn
Device: 3AG9K24724000705 (auto-detected)
==================================================

Task: 打开微信,向我的微信好友‘***’发起视频聊天,同时请使用前置摄像头

Exception in thread Thread-13 (_readerthread):
Traceback (most recent call last):
  File "C:\Users\ASUS\AppData\Roaming\uv\python\cpython-3.12.3-windows-x86_64-none\Lib\threading.py", line 1073, in _bootstrap_inner
    self.run()
  File "C:\Users\ASUS\AppData\Roaming\uv\python\cpython-3.12.3-windows-x86_64-none\Lib\threading.py", line 1010, in run
    self._target(*self._args, **self._kwargs)
  File "C:\Users\ASUS\AppData\Roaming\uv\python\cpython-3.12.3-windows-x86_64-none\Lib\subprocess.py", line 1599, in _readerthread
    buffer.append(fh.read())
                  ^^^^^^^^^
UnicodeDecodeError: 'gbk' codec can't decode byte 0xb4 in position 70: illegal multibyte sequence
Traceback (most recent call last):
  File "C:\Users\ASUS\mywork\openAutoGLM\Open-AutoGLM\main.py", line 546, in <module>
    main()
  File "C:\Users\ASUS\mywork\openAutoGLM\Open-AutoGLM\main.py", line 516, in main
    result = agent.run(args.task)
             ^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\ASUS\mywork\openAutoGLM\Open-AutoGLM\phone_agent\agent.py", line 98, in run
    result = self._execute_step(task, is_first=True)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\ASUS\mywork\openAutoGLM\Open-AutoGLM\phone_agent\agent.py", line 144, in _execute_step
    current_app = get_current_app(self.agent_config.device_id)
                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\ASUS\mywork\openAutoGLM\Open-AutoGLM\phone_agent\adb\device.py", line 30, in get_current_app
    for line in output.split("\n"):
                ^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'split'

Expected behavior / 期待表现

这里判断应该是Windows读取adb命令,同时GBK和UTF-8编码冲突造成的问题。所以关键在于手动向代码的ADB控制中添加指定使用UTF8

我对adb中device文件subprocess调用部分进行修改,问题即可解决
/phone_agent/adb/device.py

line 24

    result = subprocess.run(
        adb_prefix + ["shell", "dumpsys", "window"], capture_output=True, text=True,encoding="utf-8",errors='ignore'#这里encode和errors添加之后即可正常运行
    )
    output = result.stdout

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions