MCPcopy Create free account
hub / github.com/SuperJJ007/CSSwitch / http_get_json

Function http_get_json

proxy/csswitch_proxy.py:304–319  ·  view source on GitHub ↗

GET 上游并解析 JSON(relay 回源拉 /v1/models 用)。连接抖动重试,服务端明确响应不重试。

(url, headers, attempts=3, timeout=30)

Source from the content-addressed store, hash-verified

302
303
304def http_get_json(url, headers, attempts=3, timeout=30):
305 """GET 上游并解析 JSON(relay 回源拉 /v1/models 用)。连接抖动重试,服务端明确响应不重试。"""
306 headers = {"User-Agent": UPSTREAM_UA, **headers}
307 for i in range(attempts):
308 req = urllib.request.Request(url, headers=headers, method="GET")
309 try:
310 with urllib.request.urlopen(req, timeout=timeout) as r:
311 return json.loads(r.read())
312 except urllib.error.HTTPError:
313 raise
314 except Exception as e:
315 if i < attempts - 1:
316 log(f" ~ 上游连接抖动,重试 {i + 1}/{attempts - 1}: {e}")
317 time.sleep(0.6 * (i + 1))
318 continue
319 raise
320
321
322def normalize_openai_base(base):

Callers 1

fetch_relay_modelsFunction · 0.85

Calls 1

logFunction · 0.70

Tested by

no test coverage detected