PaddlePaddle/PaddleOCR · error · ResponseFormatError

Response body is not valid JSON: {e}

Error message

Response body is not valid JSON: {e}

What it means

Error "Response body is not valid JSON: {e}" thrown in PaddlePaddle/PaddleOCR.

Source

Thrown at paddleocr/_api_client/_http.py:60


def _extract_api_message(response: requests.Response) -> str:
    try:
        payload = response.json()
    except ValueError:
        return response.text
    if isinstance(payload, dict):
        msg = extract_api_message_from_payload(payload)
        if msg:
            return msg
    return response.text


def _response_json(response: requests.Response) -> Dict[str, Any]:
    try:
        payload = response.json()
    except ValueError as e:
        raise ResponseFormatError(f"Response body is not valid JSON: {e}") from e
    if not isinstance(payload, dict):
        raise ResponseFormatError("Response body must be a JSON object.")
    return payload


def _response_data(response: requests.Response) -> Dict[str, Any]:
    payload = _response_json(response)
    return unwrap_api_response(payload, response.status_code)


def _job_id_from_response(response: requests.Response) -> str:
    return extract_job_id(_response_data(response))


class HTTPClient:
    def __init__(
        self,
        token: str,

View on GitHub (pinned to 2661c7c0ef)

Solutions

  1. Confirm the server actually returned JSON; check the HTTP status code and Content-Type header of the response.
  2. If a proxy or gateway returned an HTML error page, fix the proxy, credentials, or base URL.
  3. Retry the request; transient server errors can produce non-JSON bodies.

Example fix

resp = session.post(url, json=body, timeout=timeout)
print(resp.status_code, resp.headers.get("Content-Type"))
print(resp.text[:500])  # inspect the non-JSON body

When it happens

Trigger: Raised by _response_json() when requests.Response.json() fails because the body is not valid JSON.

Common situations: The HTTP response body could not be parsed as JSON. Occurs with proxy errors, HTML error pages, or truncated responses. Check network intermediaries and the endpoint URL.


AI-assisted analysis of PaddlePaddle/PaddleOCR@2661c7c0ef (2026-08-14). Data as JSON: /api/errors/7ce74b3c18cdb56a. Report an issue: GitHub.