check_api.py 639 B

1234567891011121314151617
  1. import urllib.request
  2. import json
  3. try:
  4. req = urllib.request.Request('http://localhost:8000/api/templates')
  5. with urllib.request.urlopen(req, timeout=5) as resp:
  6. data = json.loads(resp.read().decode('utf-8'))
  7. print(f'总模板数: {len(data)}')
  8. models = sorted(set(t['machine_model'] for t in data))
  9. print(f'机型: {models}')
  10. types = sorted(set(t['template_type'] for t in data))
  11. print(f'模板类型: {types}')
  12. # 打印前5个模板
  13. for t in data[:5]:
  14. print(f" - {t['id']}: {t['name']}")
  15. except Exception as e:
  16. print(f'Error: {e}')