MCPcopy Create free account
hub / github.com/Tron521/codex-console-temp / test_codex2api_connection

Function test_codex2api_connection

src/core/upload/codex2api_upload.py:142–172  ·  view source on GitHub ↗

测试 Codex2API 连接。

(api_url: str, admin_key: str)

Source from the content-addressed store, hash-verified

140
141
142def test_codex2api_connection(api_url: str, admin_key: str) -> Tuple[bool, str]:
143 """测试 Codex2API 连接。"""
144 if not api_url:
145 return False, "API URL 不能为空"
146 if not admin_key:
147 return False, "Admin Key 不能为空"
148
149 url = normalize_codex2api_url(api_url) + "/api/admin/health"
150 headers = {"X-Admin-Key": admin_key}
151
152 try:
153 response = cffi_requests.get(
154 url,
155 headers=headers,
156 proxies=None,
157 timeout=10,
158 impersonate="chrome110",
159 )
160 if response.status_code in (200, 204):
161 return True, "Codex2API 连接测试成功"
162 if response.status_code == 401:
163 return False, "连接成功,但 Admin Key 无效"
164 if response.status_code == 403:
165 return False, "连接成功,但权限不足"
166 return False, f"服务器返回异常状态码: {response.status_code}"
167 except cffi_requests.exceptions.ConnectionError as e:
168 return False, f"无法连接到服务器: {str(e)}"
169 except cffi_requests.exceptions.Timeout:
170 return False, "连接超时,请检查网络配置"
171 except Exception as e:
172 return False, f"连接测试失败: {str(e)}"

Callers 2

test_codex2api_serviceFunction · 0.85

Calls 2

normalize_codex2api_urlFunction · 0.85
getMethod · 0.45

Tested by

no test coverage detected