{"record":{"id":"cc8ce07d5cec9b09","repo":"binary-husky/gpt_academic","slug":"doc2x-return-an-error-trace-id-trace-id-uid","errorCode":null,"errorMessage":"Doc2x return an error:\nTrace ID: {trace_id} {uid}\n{response.status_code} - {response_json}","messagePattern":"Doc2x return an error:\nTrace ID: (.+?) (.+?)\n(.+?) - (.+?)","errorType":"exception","errorClass":"RuntimeError","httpStatus":null,"severity":"error","filePath":"crazy_functions/pdf_fns/parse_pdf_via_doc2x.py","lineNumber":61,"sourceCode":"    \"\"\"\n    Make HTTP request with retry mechanism\n    \"\"\"\n    return requests.request(method, url, **kwargs)\n\n\ndef doc2x_api_response_status(response, uid=\"\"):\n    \"\"\"\n    Check the status of Doc2x API response\n    Args:\n        response_data: Response object from Doc2x API\n    \"\"\"\n    response_json = response.json()\n    response_data = response_json.get(\"data\", {})\n    code = response_json.get(\"code\", \"Unknown\")\n    meg = response_data.get(\"message\", response_json)\n    trace_id = response.headers.get(\"trace-id\", \"Failed to get trace-id\")\n    if response.status_code != 200:\n        raise RuntimeError(\n            f\"Doc2x return an error:\\nTrace ID: {trace_id} {uid}\\n{response.status_code} - {response_json}\"\n        )\n    if code in [\"parse_page_limit_exceeded\", \"parse_concurrency_limit\"]:\n        raise RuntimeError(\n            f\"Reached the limit of Doc2x:\\nTrace ID: {trace_id} {uid}\\n{code} - {meg}\"\n        )\n    if code not in [\"ok\", \"success\"]:\n        raise RuntimeError(\n            f\"Doc2x return an error:\\nTrace ID: {trace_id} {uid}\\n{code} - {meg}\"\n        )\n    return response_data\n\n\ndef 解析PDF_DOC2X_转Latex(pdf_file_path):\n    zip_file_path, unzipped_folder = 解析PDF_DOC2X(pdf_file_path, format=\"tex\")\n    return unzipped_folder\n\n","sourceCodeStart":43,"sourceCodeEnd":79,"githubUrl":"https://github.com/binary-husky/gpt_academic/blob/d6bde0fa54373309bd05823a49bda8da019d2c77/crazy_functions/pdf_fns/parse_pdf_via_doc2x.py#L43-L79","documentation":"doc2x_api_response_status raises this when the Doc2x (v2.noedgeai.com) REST API returns a non-200 HTTP status. The message includes the trace-id response header, caller-supplied uid, status code, and full response JSON for support escalation. Doc2x is a paid external PDF-parsing SaaS; non-200 usually means auth or request problems.","triggerScenarios":"Invalid/expired DOC2X_API_KEY (401/403); malformed request payload (400); endpoint changes (404); server-side errors (5xx); quota fully exhausted at the HTTP layer.","commonSituations":"API key rotated or expired; missing API key config leading to 'Bearer ' + empty; sending a file larger than allowed; service outage at noedgeai.com.","solutions":["Check the status code in the message: 401/403 → refresh the Doc2x API key in config; 4xx otherwise → inspect payload; 5xx → retry later","Verify config: the doc2x_api_key variable is non-empty and matches the Doc2x console","Capture the trace-id and report to Doc2x support if the key and payload look correct","Retry with backoff for transient 5xx — the code's make_request may not retry on non-200"],"exampleFix":null,"handlingStrategy":"retry","validationCode":"def doc2x_key_configured() -> bool:\n    return bool(doc2x_api_key and doc2x_api_key.strip())  # never send 'Bearer ' empty","typeGuard":null,"tryCatchPattern":"try:\n    data = doc2x_api_response_status(res)\nexcept RuntimeError as e:\n    trace = next((l for l in str(e).splitlines() if 'Trace ID' in l), '')\n    if ' 401 ' in str(e) or ' 403 ' in str(e):\n        raise RuntimeError('Doc2x API key invalid/expired — update config') from e\n    time.sleep(2)\n    data = doc2x_api_response_status(make_request(...))  # retry once for 5xx","preventionTips":["Assert the API key is non-empty before any Doc2x call","Surface trace-id in user-facing errors for support escalation","Wrap calls with a single retry on 5xx only; never retry 4xx blindly"],"tags":["doc2x","api","http-status","authentication","external-service"],"backgroundTag":null,"analyzedSha":"d6bde0fa54373309bd05823a49bda8da019d2c77","analyzedAt":"2026-08-14T22:48:35.038Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}