57 lines
2.2 KiB
Python
57 lines
2.2 KiB
Python
#!/usr/bin/env python3
|
||
"""
|
||
检查API服务器状态和调试信息
|
||
"""
|
||
import urllib.request
|
||
import json
|
||
|
||
def check_api_status():
|
||
try:
|
||
print("=== 检查API服务器状态 ===")
|
||
|
||
# 1. 检查基础连接
|
||
url = 'http://localhost:5000/api/models'
|
||
with urllib.request.urlopen(url) as response:
|
||
print(f"✓ API服务器响应正常 (状态码: {response.status})")
|
||
|
||
# 2. 检查是否有调试输出
|
||
print("\n检查API代码中的调试输出:")
|
||
print("如果API使用了最新代码,应该在控制台看到:")
|
||
print(" DEBUG: 模型管理器目录: ...")
|
||
print(" DEBUG: 目录存在: ...")
|
||
|
||
# 3. 检查新端点是否存在
|
||
try:
|
||
test_url = 'http://localhost:5000/api/models/test'
|
||
with urllib.request.urlopen(test_url) as response:
|
||
print(f"✓ 新测试端点存在 (状态码: {response.status})")
|
||
data = response.read().decode('utf-8')
|
||
result = json.loads(data)
|
||
|
||
print(f"测试端点返回:")
|
||
print(f" 模型目录: {result.get('model_dir', 'N/A')}")
|
||
print(f" 目录存在: {result.get('dir_exists', 'N/A')}")
|
||
print(f" 找到模型: {result.get('models_found', 0)} 个")
|
||
|
||
if result.get('models_found', 0) > 0:
|
||
print("✓ 新端点工作正常,说明API代码已更新")
|
||
print("✗ 但主端点 /api/models 仍有问题")
|
||
|
||
except urllib.error.HTTPError as e:
|
||
if e.code == 404:
|
||
print("✗ 新测试端点不存在,说明API未完全重启")
|
||
else:
|
||
print(f"✗ 新测试端点错误: {e.code}")
|
||
|
||
# 4. 建议
|
||
print(f"\n=== 建议 ===")
|
||
print("1. 确认API控制台有调试输出")
|
||
print("2. 如果没有调试输出,完全停止API (Ctrl+C) 并重新启动")
|
||
print("3. 检查是否有多个Python进程在运行")
|
||
print("4. 尝试在新的终端窗口启动API")
|
||
|
||
except Exception as e:
|
||
print(f"检查失败: {e}")
|
||
|
||
if __name__ == "__main__":
|
||
check_api_status() |