MCPcopy Create free account
hub / github.com/SpaceZephyr/myskill / api_post

Function api_post

libtv-skill/scripts/_common.py:35–54  ·  view source on GitHub ↗

POST 请求 agent-im OpenAPI

(path: str, body: dict)

Source from the content-addressed store, hash-verified

33
34
35def api_post(path: str, body: dict) -> dict:
36 """POST 请求 agent-im OpenAPI"""
37 url = f"{IM_BASE.rstrip('/')}{path}"
38 data = json.dumps(body).encode("utf-8")
39 req = urllib.request.Request(
40 url,
41 data=data,
42 method="POST",
43 headers=_headers(),
44 )
45 try:
46 with urllib.request.urlopen(req, timeout=30) as resp:
47 return json.loads(resp.read().decode("utf-8"))
48 except urllib.error.HTTPError as e:
49 err_body = e.read().decode("utf-8") if e.fp else ""
50 print(f"API 错误 {e.code}: {err_body}", file=sys.stderr)
51 sys.exit(1)
52 except urllib.error.URLError as e:
53 print(f"网络错误: {e.reason}", file=sys.stderr)
54 sys.exit(1)
55
56
57def api_get(path: str) -> dict:

Callers 2

create_sessionFunction · 0.85
change_projectFunction · 0.85

Calls 1

_headersFunction · 0.85

Tested by

no test coverage detected