binary-husky/gpt_academic · error · RuntimeError

Doc2x return an error: Trace ID: {trace_id} {uid} {response.

Error message

Doc2x return an error:
Trace ID: {trace_id} {uid}
{response.status_code} - {response_json}

What it means

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.

Source

Thrown at crazy_functions/pdf_fns/parse_pdf_via_doc2x.py:61

    """
    Make HTTP request with retry mechanism
    """
    return requests.request(method, url, **kwargs)


def doc2x_api_response_status(response, uid=""):
    """
    Check the status of Doc2x API response
    Args:
        response_data: Response object from Doc2x API
    """
    response_json = response.json()
    response_data = response_json.get("data", {})
    code = response_json.get("code", "Unknown")
    meg = response_data.get("message", response_json)
    trace_id = response.headers.get("trace-id", "Failed to get trace-id")
    if response.status_code != 200:
        raise RuntimeError(
            f"Doc2x return an error:\nTrace ID: {trace_id} {uid}\n{response.status_code} - {response_json}"
        )
    if code in ["parse_page_limit_exceeded", "parse_concurrency_limit"]:
        raise RuntimeError(
            f"Reached the limit of Doc2x:\nTrace ID: {trace_id} {uid}\n{code} - {meg}"
        )
    if code not in ["ok", "success"]:
        raise RuntimeError(
            f"Doc2x return an error:\nTrace ID: {trace_id} {uid}\n{code} - {meg}"
        )
    return response_data


def 解析PDF_DOC2X_转Latex(pdf_file_path):
    zip_file_path, unzipped_folder = 解析PDF_DOC2X(pdf_file_path, format="tex")
    return unzipped_folder

View on GitHub (pinned to d6bde0fa54)

Solutions

  1. Check the status code in the message: 401/403 → refresh the Doc2x API key in config; 4xx otherwise → inspect payload; 5xx → retry later
  2. Verify config: the doc2x_api_key variable is non-empty and matches the Doc2x console
  3. Capture the trace-id and report to Doc2x support if the key and payload look correct
  4. Retry with backoff for transient 5xx — the code's make_request may not retry on non-200
Defensive patterns

Strategy: retry

Validate before calling

def doc2x_key_configured() -> bool:
    return bool(doc2x_api_key and doc2x_api_key.strip())  # never send 'Bearer ' empty

Try / catch

try:
    data = doc2x_api_response_status(res)
except RuntimeError as e:
    trace = next((l for l in str(e).splitlines() if 'Trace ID' in l), '')
    if ' 401 ' in str(e) or ' 403 ' in str(e):
        raise RuntimeError('Doc2x API key invalid/expired — update config') from e
    time.sleep(2)
    data = doc2x_api_response_status(make_request(...))  # retry once for 5xx

Prevention

When it happens

Trigger: 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.

Common situations: API key rotated or expired; missing API key config leading to 'Bearer ' + empty; sending a file larger than allowed; service outage at noedgeai.com.

Related errors


AI-assisted analysis of binary-husky/gpt_academic@d6bde0fa54 (2026-08-14). Data as JSON: /api/errors/cc8ce07d5cec9b09. Report an issue: GitHub.