GET 请求 agent-im OpenAPI
(path: str)
| 55 | |
| 56 | |
| 57 | def api_get(path: str) -> dict: |
| 58 | """GET 请求 agent-im OpenAPI""" |
| 59 | url = f"{IM_BASE.rstrip('/')}{path}" |
| 60 | req = urllib.request.Request(url, method="GET", headers=_headers()) |
| 61 | try: |
| 62 | with urllib.request.urlopen(req, timeout=30) as resp: |
| 63 | return json.loads(resp.read().decode("utf-8")) |
| 64 | except urllib.error.HTTPError as e: |
| 65 | err_body = e.read().decode("utf-8") if e.fp else "" |
| 66 | print(f"API 错误 {e.code}: {err_body}", file=sys.stderr) |
| 67 | sys.exit(1) |
| 68 | except urllib.error.URLError as e: |
| 69 | print(f"网络错误: {e.reason}", file=sys.stderr) |
| 70 | sys.exit(1) |
| 71 | |
| 72 | |
| 73 | def create_session(session_id: str = "", message: str = "") -> dict: |
no test coverage detected