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

Function test_sub2api_connection

src/core/upload/sub2api_upload.py:188–226  ·  view source on GitHub ↗

测试 Sub2API 连接(GET /api/v1/admin/accounts/data 探活) Returns: (成功标志, 消息)

(api_url: str, api_key: str)

Source from the content-addressed store, hash-verified

186
187
188def test_sub2api_connection(api_url: str, api_key: str) -> Tuple[bool, str]:
189 """
190 测试 Sub2API 连接(GET /api/v1/admin/accounts/data 探活)
191
192 Returns:
193 (成功标志, 消息)
194 """
195 if not api_url:
196 return False, "API URL 不能为空"
197 if not api_key:
198 return False, "API Key 不能为空"
199
200 url = api_url.rstrip("/") + "/api/v1/admin/accounts/data"
201 headers = {"x-api-key": api_key}
202
203 try:
204 response = cffi_requests.get(
205 url,
206 headers=headers,
207 proxies=None,
208 timeout=10,
209 impersonate="chrome110",
210 )
211
212 if response.status_code in (200, 201, 204, 405):
213 return True, "Sub2API 连接测试成功"
214 if response.status_code == 401:
215 return False, "连接成功,但 API Key 无效"
216 if response.status_code == 403:
217 return False, "连接成功,但权限不足"
218
219 return False, f"服务器返回异常状态码: {response.status_code}"
220
221 except cffi_requests.exceptions.ConnectionError as e:
222 return False, f"无法连接到服务器: {str(e)}"
223 except cffi_requests.exceptions.Timeout:
224 return False, "连接超时,请检查网络配置"
225 except Exception as e:
226 return False, f"连接测试失败: {str(e)}"

Callers 2

test_sub2api_serviceFunction · 0.85

Calls 1

getMethod · 0.45

Tested by

no test coverage detected