Bug: wiki.py sources/knowledge 子目录未创建导致 /ask 接口 500 #1

Open
opened 2026-05-22 04:25:51 +00:00 by taolm · 0 comments
Owner

问题描述

访问 /ask 接口提问时报 500 错误:

FileNotFoundError: [Errno 2] No such file or directory:
  .../data/student_xxxxx/sources/session_2026-05-22T07-21-09.700230.json

前端表现为「网络出现点问题」。

原因分析

tutor/wiki.pyStudentWiki.__init__mkdirwiki_dir,但没有创建子目录 sources_dirknowledge_diringest_session() 直接往 sources_dir 写文件时目录不存在。

修复方案

__init__ 末尾、_ensure_schema() 之前补上:

self.sources_dir.mkdir(exist_ok=True)
self.knowledge_dir.mkdir(exist_ok=True)

复现步骤

  1. python app.py
  2. 浏览器打开 http://localhost:8765
  3. 输入任意问题点击提问
  4. 前端显示「网络出现点问题」

环境

  • Python 3.9.6 / macOS
  • Flask 3.1.3
## 问题描述 访问 `/ask` 接口提问时报 500 错误: ``` FileNotFoundError: [Errno 2] No such file or directory: .../data/student_xxxxx/sources/session_2026-05-22T07-21-09.700230.json ``` 前端表现为「网络出现点问题」。 ## 原因分析 `tutor/wiki.py` 的 `StudentWiki.__init__` 只 `mkdir` 了 `wiki_dir`,但没有创建子目录 `sources_dir` 和 `knowledge_dir`。`ingest_session()` 直接往 `sources_dir` 写文件时目录不存在。 ## 修复方案 在 `__init__` 末尾、`_ensure_schema()` 之前补上: ```python self.sources_dir.mkdir(exist_ok=True) self.knowledge_dir.mkdir(exist_ok=True) ``` ## 复现步骤 1. python app.py 2. 浏览器打开 http://localhost:8765 3. 输入任意问题点击提问 4. 前端显示「网络出现点问题」 ## 环境 - Python 3.9.6 / macOS - Flask 3.1.3
Sign in to join this conversation.
No Label
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: taolm/math-tutor#1
No description provided.