PaddlePaddle/PaddleOCR · warning · InvalidRequestError

OCR result is required.

Error message

OCR result is required.

What it means

InvalidRequestError raised by save_ocr_result_resources when its result argument is None. Client-side guard before any directory check or download — the OCRResult object itself is the missing input.

Source

Thrown at paddleocr/_api_client/_resources.py:71

    try:
        response.raise_for_status()
    except requests.RequestException as e:
        raise NetworkError(f"Failed to download resource: {e}") from e

    _atomic_write(target, response.content, overwrite)
    return str(target)


def save_ocr_result_resources(
    result: OCRResult,
    destination: str,
    *,
    overwrite: bool = False,
    timeout: float = 300.0,
) -> List[str]:
    if result is None:
        raise InvalidRequestError("OCR result is required.")
    dest_dir = _require_existing_directory(destination)
    saved_paths = []
    for index, page in enumerate(result.pages):
        if not page.ocr_image_url:
            continue
        filename = f"ocr-page-{index + 1}{_safe_resource_extension(page.ocr_image_url)}"
        saved_paths.append(
            save_resource(
                page.ocr_image_url,
                str(dest_dir / filename),
                overwrite=overwrite,
                timeout=timeout,
            )
        )
    return saved_paths


def save_document_parsing_result_resources(

View on GitHub (pinned to 2661c7c0ef)

Solutions

  1. Ensure you pass a parsed OCRResult from the OCR flow (poll + parse), not None and not the raw payload
  2. Check for None at the call site and surface a clearer error with context about which step failed
  3. If a helper can legitimately return None, branch on it before calling this function

Example fix

# before
save_ocr_result_resources(maybe_result, dest)  # maybe_result is None on error path

# after
if result is None:
    raise RuntimeError("OCR job produced no result; check job status")
save_ocr_result_resources(result, dest)
Defensive patterns

Strategy: validation

Validate before calling

if result is None or not getattr(result, 'pages', None):
    raise RuntimeError('no OCR result to save; check job status first')

Type guard

from paddleocr._api_client.results import OCRResult
def is_ocr_result(o) -> bool:
    return isinstance(o, OCRResult) and hasattr(o, 'pages')

Try / catch

try:
    save_ocr_result_resources(result, dest_dir)
except InvalidRequestError as e:
    raise RuntimeError(f'OCR pipeline produced no result: {e}') from e

Prevention

When it happens

Trigger: Calling save_ocr_result_resources(None, dest), typically because a variable holding the OCRResult was assigned on a branch that did not run (e.g. an error path left it None) or a refactor changed the function's return shape.

Common situations: Result assigned inside try/except and used after the except block; helper returns None on failure and caller forgets to check; passing the raw JSONL instead of the parsed OCRResult object.

Related errors


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