Skip to content

课程名含 \xa0(不间断空格)时 UnicodeEncodeError 崩溃 #602

Description

@GuZhi223

Bug 描述

当课程名称中包含 \xa0(不间断空格,来自超星 HTML 的  )时,程序在输出课程列表阶段崩溃,抛出 UnicodeEncodeError

复现步骤

  1. 准备一个账号,其课程列表中存在课程名含 \xa0 字符的课程
  2. 通过其他程序以子进程方式调用 chaoxing.exe -c config.ini(stdin 不连接控制台)
  3. 程序输出前几门正常课程后崩溃

错误信息

UnicodeEncodeError: 'gbk' codec can't encode character '\xa0' in position 24: illegal multibyte sequence

Traceback (most recent call last):
  File "main.py", line 521, in main
  File "main.py", line 448, in filter_courses
UnicodeEncodeError: 'gbk' codec can't encode character '\xa0' in position 24: illegal multibyte sequence

崩溃发生在 filter_courses 函数的 print() 调用处(main.py:448)。PyInstaller 打包后 stdout 使用系统默认 GBK 编码,无法处理 \xa0 字符。

环境

  • 系统:Windows 11 中文版
  • chaoxing 版本:最新 Release(PyInstaller 打包版)
  • Python 环境:通过 PyInstaller 打包的 exe 运行

建议修复

main.py 开头添加:

import sys
sys.stdout.reconfigure(encoding='gb18030', errors='replace')
sys.stderr.reconfigure(encoding='gb18030', errors='replace')

或在 PyInstaller 打包时设置 PYTHONIOENCODING=utf-8,确保 exe 的 stdout 使用能处理所有 Unicode 字符的编码(如 GB18030 或 UTF-8)。

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions