#!/usr/bin/env python3 """ 测试API接口 """ import requests import json def test_api(): """测试API接口""" print("=== 测试API接口 ===") try: # 测试获取宝箱列表 response = requests.get("http://localhost:8000/api/chests") print(f"Status Code: {response.status_code}") print(f"Headers: {response.headers}") if response.status_code == 200: chests = response.json() print(f"获取到 {len(chests)} 个宝箱") print("宝箱数据:") for chest in chests: print(f" ID: {chest['id']}, Title: {chest['title']}, Status: {chest['status']}, Time Remaining: {chest.get('time_remaining', 'N/A')}") else: print(f"Error: {response.text}") except Exception as e: print(f"请求错误: {e}") if __name__ == "__main__": test_api()