Files
mousehold/apps/local-agent/mousehold_agent/http.py
2026-06-28 13:48:15 +02:00

18 lines
471 B
Python

from __future__ import annotations
import json
from typing import Any
from urllib import request
def post_json(url: str, payload: dict[str, Any]) -> dict[str, Any]:
body = json.dumps(payload).encode("utf-8")
req = request.Request(
url,
data=body,
headers={"Content-Type": "application/json"},
method="POST",
)
with request.urlopen(req, timeout=30) as response:
return json.loads(response.read().decode("utf-8"))