PaddlePaddle/PaddleOCR · warning · InvalidRequestError

resource_url is required.

Error message

resource_url is required.

What it means

InvalidRequestError raised by save_resource when resource_url is falsy (empty string or None). It is a client-side argument guard run before any URL parsing or network I/O — nothing has been requested yet when it fires.

Source

Thrown at paddleocr/_api_client/_resources.py:36

from typing import Dict, Iterable, List, Optional, Tuple
from urllib.parse import unquote, urlparse

import requests

from .errors import InvalidRequestError, NetworkError, RequestTimeoutError
from .results import DocParsingResult, OCRResult


def save_resource(
    resource_url: str,
    destination: str,
    *,
    overwrite: bool = False,
    filename: Optional[str] = None,
    timeout: float = 300.0,
) -> str:
    if not resource_url:
        raise InvalidRequestError("resource_url is required.")
    if not destination:
        raise InvalidRequestError("destination is required.")

    parsed_url = urlparse(resource_url)
    if parsed_url.scheme not in ("http", "https") or not parsed_url.netloc:
        raise InvalidRequestError(f"Invalid resource URL: {resource_url}")

    target = _resolve_destination(parsed_url.path, destination, filename)
    _require_writable_target(target, overwrite)

    try:
        response = requests.get(resource_url, timeout=timeout)
    except requests.Timeout as e:
        raise RequestTimeoutError(f"Request timed out: {e}") from e
    except requests.ConnectionError as e:
        raise NetworkError(f"Connection failed: {e}") from e

    try:

View on GitHub (pinned to 2661c7c0ef)

Solutions

  1. Check the caller: log the value being passed and find why it is empty
  2. Guard before calling: skip empty URLs or raise a domain-specific error with context (which page/field was empty)
  3. If the URL should never be empty, validate upstream data (the result payload) for missing fields

Example fix

# before
save_resource(page.ocr_image_url, dest)  # crashes when URL is ''

# after
if page.ocr_image_url:
    save_resource(page.ocr_image_url, dest)
Defensive patterns

Strategy: validation

Validate before calling

if not resource_url:
    raise ValueError(f"resource_url is empty (field={field_name!r})")

Type guard

def is_http_url(u) -> bool:
    return isinstance(u, str) and u.startswith(('http://', 'https://')) and len(u) > 8

Try / catch

from paddleocr._api_client.errors import InvalidRequestError
try:
    save_resource(url, dest)
except InvalidRequestError as e:
    logger.warning("skipping resource: %s", e)  # treat empty URLs as non-fatal

Prevention

When it happens

Trigger: Calling save_resource('', dest) or save_resource(None, dest) directly; or higher-level helpers passing through an empty URL field from a result payload (e.g. a page whose ocr_image_url is empty — though save_ocr_result_resources skips those, direct calls do not).

Common situations: Programmatically extracting URLs from a result object where some fields are legitimately empty and forgetting the empty check; refactoring that renames fields and silently yields None; calling save_resource with a variable that was never assigned on an error path.

Related errors


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