115 lines
4.6 KiB
Python
115 lines
4.6 KiB
Python
#!/usr/bin/env python3
|
||
"""
|
||
最终验证所有修复
|
||
"""
|
||
import urllib.request
|
||
import json
|
||
|
||
def final_verification():
|
||
try:
|
||
print("=== 最终验证API修复 ===")
|
||
|
||
# 1. 检查API版本
|
||
print("\n1. 检查API版本:")
|
||
try:
|
||
with urllib.request.urlopen('http://localhost:5000/api/version') as response:
|
||
data = response.read().decode('utf-8')
|
||
result = json.loads(data)
|
||
|
||
print(f"API版本: {result.get('version', 'unknown')}")
|
||
print(f"修复功能: {', '.join(result.get('features', []))}")
|
||
|
||
if result.get('version') == '2.0-fixed':
|
||
print("✓ API已更新到最新版本")
|
||
else:
|
||
print("❌ API版本不匹配,可能需要重启")
|
||
|
||
except Exception as e:
|
||
print(f"❌ 版本检查失败: {e}")
|
||
print("可能需要重启API服务器")
|
||
return
|
||
|
||
# 2. 测试模型详情(如果API版本正确)
|
||
print("\n2. 测试模型详情:")
|
||
|
||
# 获取模型列表
|
||
with urllib.request.urlopen('http://localhost:5000/api/models') as response:
|
||
data = response.read().decode('utf-8')
|
||
result = json.loads(data)
|
||
models = result.get('data', [])
|
||
|
||
if models:
|
||
# 测试第一个模型
|
||
model = models[0]
|
||
model_type = model.get('model_type', '')
|
||
product_id = model.get('product_id', '')
|
||
|
||
details_url = f'http://localhost:5000/api/models/{model_type}/{product_id}/details'
|
||
print(f"测试: {details_url}")
|
||
|
||
try:
|
||
with urllib.request.urlopen(details_url) as response:
|
||
print(f"✓ 状态码: {response.status}")
|
||
|
||
details_data = response.read().decode('utf-8')
|
||
details_result = json.loads(details_data)
|
||
|
||
if details_result.get('status') == 'success':
|
||
print("✓ 模型详情: 成功获取")
|
||
|
||
data_obj = details_result.get('data', {})
|
||
training_metrics = data_obj.get('training_metrics', {})
|
||
|
||
if training_metrics:
|
||
print("✓ 训练指标:")
|
||
for metric in ['RMSE', 'MAE', 'R2', 'MAPE']:
|
||
if metric in training_metrics:
|
||
value = training_metrics[metric]
|
||
print(f" {metric}: {value}")
|
||
else:
|
||
print("⚠ 训练指标为空")
|
||
else:
|
||
print(f"❌ 模型详情错误: {details_result.get('message', '未知')}")
|
||
|
||
except urllib.error.HTTPError as e:
|
||
print(f"❌ HTTP错误: {e.code}")
|
||
if e.code == 404:
|
||
print("模型文件未找到,可能是文件名格式问题")
|
||
except Exception as e:
|
||
print(f"❌ 请求异常: {e}")
|
||
else:
|
||
print("❌ 没有可用模型进行测试")
|
||
|
||
# 3. 测试CORS
|
||
print("\n3. 测试CORS:")
|
||
try:
|
||
req = urllib.request.Request('http://localhost:5000/api/models', method='OPTIONS')
|
||
req.add_header('Origin', 'http://localhost:5173')
|
||
|
||
with urllib.request.urlopen(req) as response:
|
||
if response.status == 200:
|
||
print("✓ CORS预检: 通过")
|
||
else:
|
||
print(f"⚠ CORS预检: {response.status}")
|
||
except Exception as e:
|
||
print(f"❌ CORS测试失败: {e}")
|
||
|
||
# 4. 总结
|
||
print(f"\n=== 修复状态总结 ===")
|
||
print("已完成的修复:")
|
||
print("✓ 1. 模型列表分页功能")
|
||
print("✓ 2. 模型详情端点文件名匹配")
|
||
print("✓ 3. CORS跨域配置增强")
|
||
print("✓ 4. API日志记录改善")
|
||
print("✓ 5. 评估指标数据结构")
|
||
|
||
print(f"\n重启API服务器后应该解决:")
|
||
print("- api/models/<model_type>/<product_id>/details 404错误")
|
||
print("- strict-origin-when-cross-origin CORS错误")
|
||
print("- 模型管理页面功能异常")
|
||
|
||
except Exception as e:
|
||
print(f"验证失败: {e}")
|
||
|
||
if __name__ == "__main__":
|
||
final_verification() |