18 lines
471 B
Python
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"))
|