#!/usr/bin/env python3 """ 系统API端点测试脚本 """ import requests import json import time def test_system_endpoints(): """测试系统API端点""" base_url = "http://localhost:8000/api/v1" # 等待服务器启动 print("等待服务器启动...") time.sleep(3) endpoints = [ "/system/machine-code", "/system/info", "/system/machine-code/detailed", "/system/health" ] for endpoint in endpoints: try: print(f"\n=== 测试端点: {endpoint} ===") response = requests.get(f"{base_url}{endpoint}", timeout=10) print(f"状态码: {response.status_code}") if response.status_code == 200: data = response.json() print(f"响应: {json.dumps(data, indent=2, ensure_ascii=False)}") else: print(f"错误响应: {response.text}") except requests.exceptions.ConnectionError: print("连接失败,服务器可能未启动") except requests.exceptions.Timeout: print("请求超时") except Exception as e: print(f"请求异常: {e}") if __name__ == "__main__": test_system_endpoints()