test01.py 934 B

123456789101112131415161718192021222324252627282930313233343536373839
  1. import requests
  2. # 基础 URL
  3. base_url = 'http://192.168.31.243:7745/api/cards/card_list'
  4. # 查询参数 (query parameters)
  5. params = {
  6. 'skip': 0,
  7. 'limit': 100
  8. }
  9. # 请求头 (headers)
  10. headers = {
  11. 'accept': 'application/json'
  12. }
  13. try:
  14. # 发送 GET 请求
  15. response = requests.get(base_url, params=params, headers=headers)
  16. # 检查响应状态码
  17. response.raise_for_status()
  18. # 打印响应内容 (JSON格式)
  19. data = response.json()
  20. print("Success! Response Data:")
  21. print(data)
  22. # 打印状态码
  23. print(f"Status Code: {response.status_code}")
  24. except requests.exceptions.HTTPError as errh:
  25. print(f"Http Error: {errh}")
  26. except requests.exceptions.ConnectionError as errc:
  27. print(f"Error Connecting: {errc}")
  28. except requests.exceptions.Timeout as errt:
  29. print(f"Timeout Error: {errt}")
  30. except requests.exceptions.RequestException as err:
  31. print(f"An Error Occurred: {err}")