test01.py 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import requests
  2. import torch
  3. def send(url):
  4. # 请求头 (headers)
  5. headers = {
  6. 'accept': 'application/json'
  7. }
  8. try:
  9. # 发送 GET 请求
  10. response = requests.get(url, headers=headers)
  11. # 检查响应状态码
  12. response.raise_for_status()
  13. # 打印响应内容 (JSON格式)
  14. data = response.json()
  15. print("Success! Response Data:")
  16. print(data)
  17. # 打印状态码
  18. print(f"Status Code: {response.status_code}")
  19. except requests.exceptions.HTTPError as errh:
  20. print(f"Http Error: {errh}")
  21. except requests.exceptions.ConnectionError as errc:
  22. print(f"Error Connecting: {errc}")
  23. except requests.exceptions.Timeout as errt:
  24. print(f"Timeout Error: {errt}")
  25. except requests.exceptions.RequestException as err:
  26. print(f"An Error Occurred: {err}")
  27. if __name__ == '__main__':
  28. # base_url = 'http://127.0.0.1:7745/api/cards/query/1'
  29. # base_url = 'http://127.0.0.1:7745/api/cards/query_next/14'
  30. base_url = 'http://192.168.77.78:7745/api/cards/query/3'
  31. # base_url = 'http://192.168.77.78:7745/api/cards/query_next/3'
  32. send(base_url)