""" 测试脚本:通过后端 API 检查是否能获取 300750.SZ 的 tax_to_ebt 数据 """ import requests import json def test_api(): # 假设后端运行在默认端口 url = "http://localhost:8000/api/financials/china/300750.SZ?years=5" try: print(f"正在请求 API: {url}") response = requests.get(url, timeout=30) if response.status_code == 200: data = response.json() print(f"\n✅ API 请求成功") print(f"股票代码: {data.get('ts_code')}") print(f"公司名称: {data.get('name')}") # 检查 series 中是否有 tax_to_ebt series = data.get('series', {}) if 'tax_to_ebt' in series: print(f"\n✅ 找到 tax_to_ebt 数据!") tax_data = series['tax_to_ebt'] print(f"数据条数: {len(tax_data)}") print(f"\n最近几年的 tax_to_ebt 值:") for item in tax_data[-5:]: # 显示最近5年 year = item.get('year') value = item.get('value') month = item.get('month') month_str = f"Q{((month or 12) - 1) // 3 + 1}" if month else "" print(f" {year}{month_str}: {value}") else: print(f"\n❌ 未找到 tax_to_ebt 数据") print(f"可用字段: {list(series.keys())[:20]}...") # 检查是否有其他税率相关字段 tax_keys = [k for k in series.keys() if 'tax' in k.lower()] if tax_keys: print(f"\n包含 'tax' 的字段: {tax_keys}") else: print(f"❌ API 请求失败: {response.status_code}") print(f"响应内容: {response.text}") except requests.exceptions.ConnectionError: print("❌ 无法连接到后端服务,请确保后端正在运行(例如运行 python dev.py)") except Exception as e: print(f"❌ 请求出错: {e}") import traceback traceback.print_exc() if __name__ == "__main__": test_api()