#!/usr/bin/env python3 """ 简单测试模型详情端点 """ import urllib.request import json def simple_details_test(): try: print("=== 简单测试模型详情端点 ===") # 测试已知的端点 test_urls = [ 'http://localhost:5000/api/models/kan_optimized/P001/details', 'http://localhost:5000/api/models/transformer/P003/details', 'http://localhost:5000/api/models/mlstm/P001/details' ] for url in test_urls: print(f"\n测试: {url}") try: with urllib.request.urlopen(url) as response: print(f"状态码: {response.status}") data = response.read().decode('utf-8') result = json.loads(data) if result.get('status') == 'success': print("响应: SUCCESS") data_obj = result.get('data', {}) print(f"包含字段: {list(data_obj.keys())}") else: print(f"响应: ERROR - {result.get('message', '未知')}") except urllib.error.HTTPError as e: print(f"HTTP错误: {e.code}") try: error_data = e.read().decode('utf-8') error_result = json.loads(error_data) print(f"错误信息: {error_result.get('error', '无详情')}") except: print("无法解析错误响应") except Exception as e: print(f"请求异常: {str(e)[:100]}") print(f"\n=== CORS问题诊断 ===") print("如果前端有strict-origin-when-cross-origin错误:") print("1. 检查前端是否使用HTTPS而API使用HTTP") print("2. 检查端口是否匹配") print("3. 检查前端baseURL配置") except Exception as e: print(f"测试失败: {e}") if __name__ == "__main__": simple_details_test()