PaddlePaddle/PaddleOCR · error · FileNotFoundError

{file_path}

Error message

{file_path}

What it means

FileNotFoundError from submit_file in the async API client when os.path.exists(file_path) is false before uploading. The check runs synchronously before building the aiohttp multipart form, so a bad local path fails fast rather than as a network error.

Source

Thrown at paddleocr/_api_client/_async_http.py:117

        async with self._session.post(
            self._jobs_url,
            json=body,
            headers={"Content-Type": "application/json"},
        ) as resp:
            await self._raise_for_response(resp)
            data = await self._response_data(resp)
            return extract_job_id(data)

    async def submit_file(
        self,
        model: str,
        file_path: str,
        optional_payload: dict,
        page_ranges: Optional[str] = None,
        batch_id: Optional[str] = None,
    ) -> str:
        if not os.path.exists(file_path):
            raise FileNotFoundError(file_path)

        form = aiohttp.FormData()
        form.add_field("model", model)
        form.add_field("optionalPayload", json.dumps(optional_payload))
        if page_ranges is not None:
            form.add_field("pageRanges", page_ranges)
        if batch_id is not None:
            form.add_field("batchId", batch_id)

        with open(file_path, "rb") as f:
            file_data = f.read()
        form.add_field(
            "file",
            file_data,
            filename=os.path.basename(file_path),
        )

        await self._ensure_session()

View on GitHub (pinned to 2661c7c0ef)

Solutions

  1. Pass an absolute path: `str(Path(file_path).resolve())` at submission time.
  2. Verify with os.path.isfile (not just exists) before submitting.
  3. For files that may vanish, read bytes earlier or hold the file open until the upload starts.

Example fix

// before
job = await http.submit_file(model, "./tmp/scan.pdf", {})

// after
from pathlib import Path
job = await http.submit_file(model, str(Path("./tmp/scan.pdf").resolve()), {})
Defensive patterns

Strategy: validation

Validate before calling

import os

def submittable_file(file_path: str) -> bool:
    return os.path.isfile(file_path)

Type guard

from pathlib import Path

def is_existing_file(value: object) -> bool:
    return isinstance(value, (str, os.PathLike)) and Path(value).is_file()

Try / catch

try:
    job_id = await http.submit_file(model, file_path, payload)
except FileNotFoundError:
    file_path = str(Path(file_path).resolve())
    if not Path(file_path).is_file():
        raise
    job_id = await http.submit_file(model, file_path, payload)

Prevention

When it happens

Trigger: Calling the async document-parsing client's file submission with a relative path from a different cwd; the file deleted/moved between queueing and submission; a directory (exists but read fails later) or plain typo in the path string.

Common situations: Async pipelines where the path was computed in another task/worker with a different cwd; temp files cleaned up by the time the upload coroutine runs.

Related errors


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