binary-husky/gpt_academic · error · ValueError
无法读取以下数据,请检查配置。 {chunk_decoded}
Error message
无法读取以下数据,请检查配置。
{chunk_decoded} What it means
ValueError raised inside the predict (streaming UI) path when a received chunk is non-empty, is not the 'data: [DONE]' sentinel, and fails to parse into a chunkjson (chunkjson is None). The bridge expected SSE 'data:' frames but got something unreadable — usually an HTML error page, a proxy/auth interstitial, or a relay heartbeat — and refuses to continue with unparseable data. The offending raw chunk is embedded in the message.
Source
Thrown at request_llms/bridge_chatgpt.py:358
return
# 提前读取一些信息 (用于判断异常)
chunk_decoded, chunkjson, has_choices, choice_valid, has_content, has_role = decode_chunk(chunk)
if is_head_of_the_stream and (r'"object":"error"' not in chunk_decoded) and (r"content" not in chunk_decoded):
# 数据流的第一帧不携带content
is_head_of_the_stream = False; continue
if "error" in chunk_decoded: logger.error(f"接口返回了未知错误: {chunk_decoded}")
if chunk:
try:
if has_choices and not choice_valid:
# 一些垃圾第三方接口的出现这样的错误
continue
if ('data: [DONE]' not in chunk_decoded) and len(chunk_decoded) > 0 and (chunkjson is None):
# 传递进来一些奇怪的东西
raise ValueError(f'无法读取以下数据,请检查配置。\n\n{chunk_decoded}')
# 前者是API2D & One-API的结束条件,后者是OPENAI的结束条件
one_api_terminate = ('data: [DONE]' in chunk_decoded)
openai_terminate = (has_choices) and (len(chunkjson['choices'][0]["delta"]) == 0)
if one_api_terminate or openai_terminate:
is_termination_certain = False
if one_api_terminate: is_termination_certain = True # 抓取符合规范的结束条件
elif (has_choices) and (chunkjson['choices'][0].get('finish_reason', 'null') == 'stop'): is_termination_certain = True # 抓取符合规范的结束条件
if is_termination_certain:
reach_termination = True
log_chat(llm_model=llm_kwargs["llm_model"], input_str=inputs, output_str=gpt_replying_buffer)
break # 对于符合规范的接口,这里可以break
else:
continue # 对于不符合规范的接口,这里需要继续
# 到这里,我们已经可以假定必须包含choice了
try:
status_text = f"finish_reason: {chunkjson['choices'][0].get('finish_reason', 'null')}"
except:
logger.error(f"一些第三方接口出现这样的错误,兼容一下吧: {chunk_decoded}")View on GitHub (pinned to d6bde0fa54)
Solutions
- Check the chunk_decoded text printed in the error — an HTML title (404/502/Cloudflare) immediately identifies the layer that broke.
- Fix API_URL_REDIRECT in config_private.py to the exact chat/completions path of your provider.
- Bypass corporate proxies / VPN for the API host, or add the proxy exclusion, then retry.
- If the relay is flaky, switch to another channel/key or the official endpoint.
Example fix
# before API_URL_REDIRECT = "https://my-relay.com" # after API_URL_REDIRECT = "https://my-relay.com/v1/chat/completions"
Defensive patterns
Strategy: validation
Validate before calling
import requests
r = requests.post(api_url, headers=headers, json={'model': model, 'messages': [{'role':'user','content':'ping'}], 'max_tokens': 1}, stream=True, timeout=10)
first = next(r.iter_lines()).decode(errors='replace')
assert first.startswith('data:'), f"endpoint returns non-SSE first frame: {first[:120]}" Try / catch
try:
yield from predict(inputs, llm_kwargs, plugin_kwargs, chatbot, history)
except ValueError as e:
if '无法读取以下数据' in str(e):
report_and_fix_endpoint(str(e)) # HTML body in error => wrong URL or proxy
else:
raise Prevention
- Smoke-test custom API URLs with a one-token streaming request before real use.
- Ensure API_URL_REDIRECT ends with the exact /v1/chat/completions style path.
- Keep the network path to the API free of HTML-injecting proxies (captive portals, corporate MITM).
- Embed the raw failing chunk in bug reports — it names the offending layer instantly.
When it happens
Trigger: API_URL_REDIRECT pointing at a wrong path returning HTML (404/502 pages); Cloudflare or corporate proxy intercepting the request; the relay returning empty-body keepalives or non-JSON comments mid-stream; chunk did start with 'data:' per outer checks but its JSON payload is corrupt, leaving chunkjson None.
Common situations: Misconfigured custom API host (missing /v1/chat/completions suffix); reverse-proxy (nginx) error pages injected into the stream; free relay services with flaky SSE framing; TLS-intercepting corporate proxies mangling chunk boundaries.
Related errors
AI-assisted analysis of binary-husky/gpt_academic@d6bde0fa54 (2026-08-14).
Data as JSON: /api/errors/dcfa75f635758d11.
Report an issue: GitHub.