{"record":{"id":"3eeccaf5e6047bfd","repo":"binary-husky/gpt_academic","slug":"json-3eecca","errorCode":null,"errorMessage":"Json解析不合常规","messagePattern":"Json解析不合常规","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"request_llms/oai_std_model_template.py","lineNumber":263,"sourceCode":"                            print(f\"[response] {result}\")\n                        break\n                    result += response_text\n                    if reasoning:\n                        reasoning_buffer += reasoning_content\n                    if observe_window is not None:\n                        # 观测窗，把已经获取的数据显示出去\n                        if len(observe_window) >= 1:\n                            observe_window[0] += response_text\n                        # 看门狗，如果超过期限没有喂狗，则终止\n                        if len(observe_window) >= 2:\n                            if (time.time() - observe_window[1]) > watch_dog_patience:\n                                raise RuntimeError(\"用户取消了程序。\")\n                except Exception as e:\n                    chunk = get_full_error(chunk, stream_response)\n                    chunk_decoded = chunk.decode()\n                    error_msg = chunk_decoded\n                    logger.error(error_msg)\n                    raise RuntimeError(\"Json解析不合常规\")\n        if reasoning:\n            paragraphs = ''.join([f'<p style=\"margin: 1.25em 0;\">{line}</p>' for line in reasoning_buffer.split('\\n')])\n            return f'''<div class=\"reasoning_process\" >{paragraphs}</div>\\n\\n''' + result\n        return result\n\n    def predict(\n        inputs,\n        llm_kwargs,\n        plugin_kwargs,\n        chatbot,\n        history=[],\n        system_prompt=\"\",\n        stream=True,\n        additional_fn=None,\n    ):\n        \"\"\"\n        发送至chatGPT，流式获取输出。\n        用于基础的对话功能。","sourceCodeStart":245,"sourceCodeEnd":281,"githubUrl":"https://github.com/binary-husky/gpt_academic/blob/d6bde0fa54373309bd05823a49bda8da019d2c77/request_llms/oai_std_model_template.py#L245-L281","documentation":"Catch-all inside the try block that processes each SSE chunk in predict_no_ui_long_connection: any exception while accumulating result/handling finish (key errors from unexpected chunk shapes, decode issues, the watchdog raise being caught too) triggers get_full_error, logger.error of the raw chunk, and RuntimeError('Json解析不合常规'). Like 188/189, the real detail is in the log; the message just says the JSON shape was unexpected.","triggerScenarios":"A chunk whose structure violates decode_chunk/accumulation assumptions: provider returns an error object where content deltas are expected, missing 'choices' field, non-JSON relay responses (HTML error pages), or schema changes in a custom OpenAI-compatible backend.","commonSituations":"Third-party relays with slightly non-standard SSE payloads; gateways returning HTML 502 pages mid-stream; provider API version changes; this catch also swallows the user-cancel watchdog raise from error 189 when cancellation coincides with chunk processing.","solutions":["Inspect logger.error output — the offending raw chunk is logged verbatim.","Point API_URL_ORIGINAL at a strictly OpenAI-compatible endpoint or fix the relay's response format.","Update decode_chunk to tolerate the provider's actual schema (e.g. missing reasoning_content).","Retry after provider-side errors resolve (502s are often transient)."],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try:\n    result = predict_no_ui_long_connection(...)\nexcept RuntimeError as e:\n    if 'Json解析不合常规' in str(e):\n        chunk = get_last_logged_chunk()  # logger.error has the raw payload\n        if is_provider_5xx(chunk):\n            backoff_and_retry()\n        else:\n            fix_or_report_schema(chunk)","preventionTips":["Always run with logging enabled; the raw chunk is the only diagnostic.","Prefer strictly OpenAI-compatible endpoints/relays.","Re-test custom providers after their API version bumps."],"tags":["openai","json","streaming","schema-mismatch","relay"],"backgroundTag":null,"analyzedSha":"d6bde0fa54373309bd05823a49bda8da019d2c77","analyzedAt":"2026-08-14T22:48:35.038Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}