MCPcopy Index your code
hub / github.com/lightningpixel/modly / _request_json

Function _request_json

tools/modly-cli/agent.py:65–85  ·  view source on GitHub ↗
(
    method: str,
    url: str,
    *,
    timeout: float,
    data: bytes | None = None,
    headers: dict[str, str] | None = None,
)

Source from the content-addressed store, hash-verified

63
64
65def _request_json(
66 method: str,
67 url: str,
68 *,
69 timeout: float,
70 data: bytes | None = None,
71 headers: dict[str, str] | None = None,
72) -> Any:
73 req = urllib.request.Request(url, data=data, method=method, headers=headers or {})
74 try:
75 with urllib.request.urlopen(req, timeout=timeout) as resp:
76 raw = resp.read().decode("utf-8")
77 except urllib.error.HTTPError as exc:
78 detail = exc.read().decode("utf-8", errors="replace")
79 raise ModlyCliError(f"HTTP {exc.code} from {url}: {detail}", code=f"HTTP_{exc.code}", http_status=exc.code) from exc
80 except urllib.error.URLError as exc:
81 raise ModlyCliError(f"Cannot reach Modly API at {url}: {exc.reason}", code="API_UNAVAILABLE") from exc
82 try:
83 return json.loads(raw) if raw else {}
84 except json.JSONDecodeError as exc:
85 raise ModlyCliError(f"Expected JSON from {url}, got: {raw[:500]}", code="INVALID_JSON_RESPONSE") from exc
86
87
88def _download(url: str, dest: Path, *, timeout: float) -> int:

Callers 15

_try_healthFunction · 0.85
_require_healthFunction · 0.85
_model_catalogFunction · 0.85
cmd_healthFunction · 0.85
cmd_statusFunction · 0.85
cmd_modelsFunction · 0.85
cmd_model_statusFunction · 0.85
_choose_auto_modelFunction · 0.85
_resolve_model_idFunction · 0.85
cmd_paramsFunction · 0.85
cmd_jobFunction · 0.85

Calls 1

ModlyCliErrorClass · 0.85

Tested by

no test coverage detected