MCPcopy Create free account
hub / github.com/codenameone/CodenameOne / http_post_json

Function http_post_json

scripts/website/syndicate_blog_posts.py:334–350  ·  view source on GitHub ↗
(url: str, headers: dict[str, str], payload: dict[str, Any])

Source from the content-addressed store, hash-verified

332
333
334def http_post_json(url: str, headers: dict[str, str], payload: dict[str, Any]) -> dict[str, Any]:
335 data = json.dumps(payload).encode("utf-8")
336 request = urllib.request.Request(url, data=data, method="POST")
337 request.add_header("Content-Type", "application/json")
338 request.add_header("User-Agent", USER_AGENT)
339 request.add_header("Accept", "application/json")
340 for key, value in headers.items():
341 request.add_header(key, value)
342 try:
343 with urllib.request.urlopen(request, timeout=60) as response:
344 body = response.read().decode("utf-8")
345 except urllib.error.HTTPError as err:
346 detail = err.read().decode("utf-8", errors="replace")
347 raise RuntimeError(f"{url} returned HTTP {err.code}: {detail}") from err
348 if not body:
349 return {}
350 return json.loads(body)
351
352
353def publish_to_devto(post: Post, body_markdown: str, api_key: str, draft: bool = False) -> dict[str, Any]:

Callers 1

publish_to_devtoFunction · 0.85

Calls 4

RequestMethod · 0.80
encodeMethod · 0.65
readMethod · 0.65
decodeMethod · 0.45

Tested by

no test coverage detected