MCPcopy Create free account
hub / github.com/GCWing/BitFun / http_post_json

Function http_post_json

src/apps/relay-server/test_incremental_upload.py:91–110  ·  view source on GitHub ↗

Returns (status_code, parsed_json_or_None).

(url: str, data: dict)

Source from the content-addressed store, hash-verified

89
90
91def http_post_json(url: str, data: dict) -> tuple:
92 """Returns (status_code, parsed_json_or_None)."""
93 try:
94 body = json.dumps(data).encode()
95 req = urllib.request.Request(url, data=body, method="POST")
96 req.add_header("Content-Type", "application/json")
97 with urllib.request.urlopen(req, timeout=10) as resp:
98 text = resp.read().decode()
99 try:
100 return resp.status, json.loads(text)
101 except json.JSONDecodeError:
102 return resp.status, text
103 except urllib.error.HTTPError as e:
104 text = e.read().decode() if e.fp else ""
105 try:
106 return e.code, json.loads(text)
107 except (json.JSONDecodeError, Exception):
108 return e.code, text
109 except Exception as e:
110 return 0, str(e)
111
112
113async def create_room_ws(room_id: str):

Callers 1

run_testsFunction · 0.85

Calls 1

readMethod · 0.45

Tested by

no test coverage detected