返回 VideoClaw
start_backend.md
根目录 / video-claw / references / run_project / start_backend.md
1 # 启动后端
2
3 启动 FastAPI 后端服务。
4
5 ## 检查是否已运行
6
7 ```bash
8 # 推荐(检查服务响应)
9 curl -s http://localhost:8000/api/health && echo "后端运行中" || echo "后端未运行"
10 ```
11
12 ## 启动命令
13
14 ```bash
15 cd video-claw/backend
16 source venv/bin/activate
17 python api_server.py
18 ```
19
20 ## 验证
21
22 ```bash
23 curl http://localhost:8000/api/health
24 ```
25
26 ## 启动后等待
27
28 ⚠️ **重要**:后端启动需要时间,启动后必须等待 **3 秒** 再调用 API,否则可能收到 404 错误。
29
30 ```bash
31 sleep 3
32 # 然后再调用 API
33 ```
34
35 ## 常见问题
36
37 | 错误 | 原因 | 解决方法 |
38 |------|------|----------|
39 | `command not found: lsof` | lsof 命令不存在 | 使用备用检查方式 `curl http://localhost:8000/api/health` |
40 | `后端未运行` | 服务未启动 | 执行启动命令 |
41 | `Address already in use` | 端口被占用 | `lsof -ti :8000 \| xargs kill` 或 `pkill -f api_server.py` |
42 | `ModuleNotFoundError` | 虚拟环境未激活 | 先执行 `source venv/bin/activate` |
43 | `Connection refused` | 服务未启动或崩溃 | 检查日志 `/tmp/movie-backend.log` |
44
45 ## 注意事项
46
47 - 后端端口:`8000`
48 - 日志位置:`/tmp/movie-backend.log`
49 - **必须确保后端运行后才能调用 API**
50
50 lines MARKDOWN