import json import urllib.error import urllib.request TOK = open("/root/.ha-token", encoding="utf-8").read().strip() KEY = open("/root/.immich-key-new", encoding="utf-8").read().strip() BASE = "http://127.0.0.1:8123" HDR = {"Authorization": "Bearer " + TOK, "Content-Type": "application/json"} def call(path, method="GET", body=None): data = json.dumps(body).encode() if body is not None else None r = urllib.request.Request(BASE + path, data=data, method=method, headers=HDR) try: with urllib.request.urlopen(r, timeout=60) as x: raw = x.read() return (json.loads(raw) if raw else {}), None except urllib.error.HTTPError as e: return None, f"HTTP {e.code}: {e.read()[:200].decode('utf-8', 'replace')}" except Exception as e: return None, str(e)[:120] # проверка ключа try: req = urllib.request.Request("http://192.168.1.104:2283/api/server/statistics", headers={"x-api-key": KEY}) with urllib.request.urlopen(req, timeout=20) as x: stats = json.loads(x.read()) print("ключ работает, фото:", stats.get("photos"), "| видео:", stats.get("videos"), "| пользователей:", stats.get("usage")) except Exception as e: print("ключ не работает:", str(e)[:100]) flow, err = call("/api/config/config_entries/flow", "POST", {"handler": "immich"}) if err: print("flow:", err) raise SystemExit(1) fid = flow["flow_id"] print("шаг:", flow.get("step_id"), "| поля:", [f.get("name") for f in (flow.get("data_schema") or [])]) res, err2 = call(f"/api/config/config_entries/flow/{fid}", "POST", { "url": "http://192.168.1.104:2283", "api_key": KEY, }) print("immich:", err2 or (res or {}).get("type"), (res or {}).get("errors"))