From 2130b23051b4a6129dcb114d9d182c8042049108 Mon Sep 17 00:00:00 2001 From: Oscar Date: Mon, 29 Dec 2025 16:53:40 +0800 Subject: [PATCH] =?UTF-8?q?fix(utils):=20=E4=BC=98=E5=8C=96=20pip=20?= =?UTF-8?q?=E5=AE=89=E8=A3=85=E8=BF=87=E7=A8=8B=E4=B8=AD=E7=9A=84=E5=AD=97?= =?UTF-8?q?=E7=AC=A6=E8=A7=A3=E7=A0=81=E9=80=BB=E8=BE=91=E4=BB=A5=E5=85=BC?= =?UTF-8?q?=E5=AE=B9=E5=A4=9A=E5=B9=B3=E5=8F=B0=E7=BC=96=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- astrbot/core/utils/pip_installer.py | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/astrbot/core/utils/pip_installer.py b/astrbot/core/utils/pip_installer.py index 6076a114a..663afc081 100644 --- a/astrbot/core/utils/pip_installer.py +++ b/astrbot/core/utils/pip_installer.py @@ -1,10 +1,29 @@ import asyncio +import locale import logging import sys logger = logging.getLogger("astrbot") +def _robust_decode(line: bytes) -> str: + """解码字节流,兼容不同平台的编码""" + try: + return line.decode("utf-8").strip() + except UnicodeDecodeError: + pass + try: + return line.decode(locale.getpreferredencoding(False)).strip() + except UnicodeDecodeError: + pass + if sys.platform.startswith("win"): + try: + return line.decode("gbk").strip() + except UnicodeDecodeError: + pass + return line.decode("utf-8", errors="replace").strip() + + class PipInstaller: def __init__(self, pip_install_arg: str, pypi_index_url: str | None = None): self.pip_install_arg = pip_install_arg @@ -42,7 +61,7 @@ async def install( assert process.stdout is not None async for line in process.stdout: - logger.info(line.decode().strip()) + logger.info(_robust_decode(line)) await process.wait()