PaddlePaddle/PaddleOCR · critical · AuthError
Token is required. Set PADDLEOCR_ACCESS_TOKEN or pass token=
Error message
Token is required. Set PADDLEOCR_ACCESS_TOKEN or pass token=.
What it means
AuthError raised by the synchronous PaddleOCRClient.__init__ when token= is empty/None and PADDLEOCR_ACCESS_TOKEN is unset. The client refuses to build without credentials so requests cannot silently go out unauthenticated.
Source
Thrown at paddleocr/_api_client/client.py:58
class PaddleOCRClient:
"""Synchronous blocking client for PaddleOCR official API.
Wraps the async job API internally: submit → poll → fetch result.
"""
def __init__(
self,
token: Optional[str] = None,
base_url: Optional[str] = None,
request_timeout: float = 300.0,
poll_timeout: float = 600.0,
client_platform: Optional[str] = None,
):
self._token = token or os.environ.get("PADDLEOCR_ACCESS_TOKEN", "")
if not self._token:
raise AuthError(
"Token is required. Set PADDLEOCR_ACCESS_TOKEN or pass token=."
)
resolved_base_url = (
base_url or os.environ.get("PADDLEOCR_BASE_URL") or DEFAULT_BASE_URL
)
self._http = HTTPClient(
self._token,
resolved_base_url,
request_timeout,
client_platform=client_platform,
)
self._poller = Poller(self._http, max_wait_time=poll_timeout)
def __enter__(self):
return self
def __exit__(self, *args):
self.close()View on GitHub (pinned to 2661c7c0ef)
Solutions
- Pass token= explicitly at construction
- Set PADDLEOCR_ACCESS_TOKEN in the launching environment (export, Dockerfile ENV, CI secret)
- Verify with a quick check: python -c "import os; print(bool(os.environ.get('PADDLEOCR_ACCESS_TOKEN')))"
Example fix
# before client = PaddleOCRClient() # after client = PaddleOCRClient(token=get_token_from_secret_store())
Defensive patterns
Strategy: validation
Validate before calling
import os
assert os.environ.get('PADDLEOCR_ACCESS_TOKEN') or TOKEN_FROM_CONFIG, 'PaddleOCR token missing' Try / catch
from paddleocr._api_client.errors import AuthError
try:
client = PaddleOCRClient(token=tok)
except AuthError as e:
log_and_alert(e) # config problem, not transient
raise Prevention
- Inject the token via your platform's secret mechanism (env, vault)
- Smoke-test client construction in CI
- Do not commit tokens; reference by name only
When it happens
Trigger: PaddleOCRClient() constructed with no arguments in an environment lacking PADDLEOCR_ACCESS_TOKEN; token set in a different shell/session than the one running the code.
Common situations: Local scripts run from an IDE that does not inherit shell env vars; Docker images that drop env vars; CI pipelines missing the secret.
Related errors
- Token is required. Set PADDLEOCR_ACCESS_TOKEN or pass token=
- PaddleOCR source adapter is not configured.
- worker mode does not support a custom fetch implementation.
- Conflicting values provided for ${label}: ${aliases.join(",
- ${warnings.join(" ")} (pipeline warnings promoted to errors
AI-assisted analysis of PaddlePaddle/PaddleOCR@2661c7c0ef (2026-08-14).
Data as JSON: /api/errors/d13442099be6cb8b.
Report an issue: GitHub.