56 lines
1.9 KiB
Python
56 lines
1.9 KiB
Python
![]() |
#!/usr/bin/env python3
|
|||
|
"""
|
|||
|
简单API测试
|
|||
|
"""
|
|||
|
|
|||
|
import requests
|
|||
|
import json
|
|||
|
|
|||
|
def test_models_api():
|
|||
|
"""测试模型API"""
|
|||
|
|
|||
|
api_url = "http://localhost:5000/api/models"
|
|||
|
|
|||
|
try:
|
|||
|
print("请求API:", api_url)
|
|||
|
response = requests.get(api_url, timeout=10)
|
|||
|
|
|||
|
print(f"状态码: {response.status_code}")
|
|||
|
|
|||
|
if response.status_code == 200:
|
|||
|
data = response.json()
|
|||
|
print("API响应结构:")
|
|||
|
print(f" status: {data.get('status')}")
|
|||
|
print(f" total: {data.get('total')}")
|
|||
|
|
|||
|
models = data.get('data', [])
|
|||
|
print(f" models count: {len(models)}")
|
|||
|
|
|||
|
for i, model in enumerate(models):
|
|||
|
print(f"\n模型 {i+1}:")
|
|||
|
print(f" model_id: '{model.get('model_id', 'MISSING')}'")
|
|||
|
print(f" filename: '{model.get('filename', 'MISSING')}'")
|
|||
|
print(f" product_id: '{model.get('product_id', 'MISSING')}'")
|
|||
|
print(f" model_type: '{model.get('model_type', 'MISSING')}'")
|
|||
|
print(f" version: '{model.get('version', 'MISSING')}'")
|
|||
|
|
|||
|
# 分析问题
|
|||
|
if not model.get('model_id'):
|
|||
|
print(" ❌ model_id为空!")
|
|||
|
if not model.get('filename'):
|
|||
|
print(" ❌ filename也为空!")
|
|||
|
else:
|
|||
|
print(f" ℹ️ filename存在: {model.get('filename')}")
|
|||
|
else:
|
|||
|
print(" ✅ model_id正常")
|
|||
|
else:
|
|||
|
print(f"请求失败: {response.text}")
|
|||
|
|
|||
|
except requests.exceptions.ConnectionError:
|
|||
|
print("❌ 无法连接到API服务器")
|
|||
|
print("请确保API服务器正在运行: python server/api.py")
|
|||
|
except Exception as e:
|
|||
|
print(f"测试失败: {e}")
|
|||
|
|
|||
|
if __name__ == "__main__":
|
|||
|
test_models_api()
|