ShopTRAINING/test/test_api_logs.py
2025-07-02 11:05:23 +08:00

56 lines
2.0 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

#!/usr/bin/env python3
"""
测试API日志输出
"""
import urllib.request
import json
import time
def test_api_logs():
try:
print("=== 测试API日志输出 ===")
print("注意检查API控制台是否有以下日志输出")
print("1. [API] 获取模型列表请求")
print("2. [API] 模型管理器目录: ...")
print("3. [API] 成功获取 X 个模型")
print("4. [API] 模型 1: id='...', filename='...'")
print()
# 发送请求
print("发送请求到 /api/models...")
url = 'http://localhost:5000/api/models'
with urllib.request.urlopen(url) as response:
data = response.read().decode('utf-8')
result = json.loads(data)
print(f"响应状态: {response.status}")
models = result.get('data', [])
print(f"返回模型数: {len(models)}")
if models:
model = models[0]
print(f"第一个模型:")
print(f" filename: '{model.get('filename', 'MISSING')}'")
print(f" model_id: '{model.get('model_id', 'MISSING')}'")
if model.get('filename') and model.get('model_id'):
print("✓ API修复成功日志应该显示正确的模型信息")
else:
print("✗ API仍有问题检查日志输出")
print("\n现在检查API控制台应该能看到详细的日志输出")
# 测试404请求应该有请求日志
print("\n发送404请求测试日志...")
try:
urllib.request.urlopen('http://localhost:5000/api/nonexistent')
except urllib.error.HTTPError as e:
print(f"预期的404错误: {e.code}")
print("检查API控制台是否显示了这个请求的日志")
except Exception as e:
print(f"测试失败: {e}")
if __name__ == "__main__":
test_api_logs()