PaddlePaddle/PaddleOCR · error · InvalidRequestError

Bad request: {msg}

Error message

Bad request: {msg}

What it means

Raised as InvalidRequestError by raise_for_status() when the HTTP response status is 400. The message embeds the service's explanation. The request was malformed or semantically invalid per the API (bad parameters, unsupported file, invalid fields), so the same request will fail again unchanged.

Source

Thrown at paddleocr/_api_client/_core.py:154

            start_time=ep.get("startTime"),
            end_time=ep.get("endTime"),
        )
    return JobStatus(
        job_id=job_id,
        state=state,
        progress=progress,
        result=data.get("resultUrl"),
        error_msg=data.get("errorMsg"),
    )


def raise_for_status(status_code: int, msg: str) -> None:
    if 200 <= status_code < 300:
        return
    if status_code in (401, 403):
        raise AuthError(f"Authentication failed: {msg}")
    if status_code == 400:
        raise InvalidRequestError(f"Bad request: {msg}")
    if status_code == 429:
        raise RateLimitError(f"Rate limit exceeded: {msg}")
    if status_code in (503, 504):
        raise ServiceUnavailableError(status_code, f"Service unavailable: {msg}")
    raise APIError(status_code, msg)


def unwrap_api_response(payload: dict, status_code: int) -> dict:
    if not isinstance(payload, dict):
        raise ResponseFormatError("Response body must be a JSON object.")
    code = payload.get("code", 0)
    if code not in (0, None):
        raise APIError(status_code, extract_api_message_from_payload(payload) or "")
    data = payload.get("data")
    if not isinstance(data, dict):
        raise ResponseFormatError("Response JSON must contain object field 'data'.")
    return data

View on GitHub (pinned to 2661c7c0ef)

Solutions

  1. Read the embedded message; it names the offending field or reason.
  2. Correct or remove the flagged parameter/option and resend.
  3. Validate the file locally (format, size, readability) before uploading.
  4. Cross-check option names and allowed values against the current API docs.
Defensive patterns

Strategy: try-catch

Try / catch

from paddleocr._api_client.errors import InvalidRequestError
try:
    result = await client.ocr(file_path=p, options=opts)
except InvalidRequestError as e:
    if str(e).startswith("Bad request"):
        log.error("fix request params: %s", e)  # not retryable
        raise

Prevention

When it happens

Trigger: Submitting a request with invalid option values, an unsupported file type, a malformed file_url, or out-of-range parameters where the service responds 400.

Common situations: Sending options fields the model does not support, URLs the service cannot fetch, base64/path mixups, or parameter names from an older API version.

Related errors


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