test_api.py 518 B

1234567891011121314
  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('总数:', len(data))
  8. models = sorted(set(t['machine_model'] for t in data))
  9. print('机型:', models)
  10. types = sorted(set(t['template_type'] for t in data))
  11. print('模板类型:', types)
  12. except Exception as e:
  13. print(f'Error: {e}')