Files
weather-info/pico-client/tryout/api_server_checker.py
2025-11-21 19:07:41 +00:00

41 lines
1.1 KiB
Python

import urequests # type: ignore
import json
# BASE_API_URL: str = "http://api-server:8000"
# BASE_API_URL: str = "http://j-agent-01:8000"
BASE_API_URL: str = "http://192.168.178.105:8000"
class API_Server_Checker:
def __init__(self):
pass
def _get_items(self, item_id: int = 0):
items_url: str = (
f"{BASE_API_URL}/items"
if item_id == 0
else f"{BASE_API_URL}/items/{item_id}"
)
print(f"query: {items_url}")
r: any
try:
r = urequests.get(items_url)
print("Status-Code:", r.status_code)
json_resp = r.json()
if r.status_code == 200:
print("json_resp:", json_resp)
else:
print("api-server error:", json_resp["error"]["message"])
except OSError as e:
print("Network error:", e)
except Exception as e:
print("Error:", e)
finally:
if r:
r.close()
def check(self, item_id: int):
self._get_items(item_id)