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

46 lines
1.5 KiB
Python

#!/usr/bin/env python
"""
测试API响应详情
"""
import requests
import json
def test_api():
"""测试API响应"""
try:
print("测试API模型端点...")
response = requests.get("http://localhost:5000/api/models", timeout=10)
print(f"状态码: {response.status_code}")
print(f"Content-Type: {response.headers.get('Content-Type')}")
print(f"响应长度: {len(response.text)}")
if response.status_code == 200:
data = response.json()
print(f"响应数据: {json.dumps(data, indent=2, ensure_ascii=False)}")
if data.get('status') == 'success':
models = data.get('data', [])
print(f"模型数量: {len(models)}")
if models:
print("第一个模型:")
for key, value in models[0].items():
print(f" {key}: {value}")
else:
print("没有找到模型")
else:
print(f"API返回错误状态: {data.get('status')}")
print(f"错误信息: {data.get('message', 'N/A')}")
else:
print(f"HTTP错误: {response.status_code}")
print(f"响应内容: {response.text}")
except requests.exceptions.RequestException as e:
print(f"请求失败: {e}")
except Exception as e:
print(f"其他错误: {e}")
if __name__ == "__main__":
test_api()