{"record":{"id":"d13442099be6cb8b","repo":"PaddlePaddle/PaddleOCR","slug":"token-is-required-set-paddleocr-access-token-or-p-d13442","errorCode":null,"errorMessage":"Token is required. Set PADDLEOCR_ACCESS_TOKEN or pass token=.","messagePattern":"Token is required\\. Set PADDLEOCR_ACCESS_TOKEN or pass token=\\.","errorType":"exception","errorClass":"AuthError","httpStatus":null,"severity":"critical","filePath":"paddleocr/_api_client/client.py","lineNumber":58,"sourceCode":"\n\nclass PaddleOCRClient:\n    \"\"\"Synchronous blocking client for PaddleOCR official API.\n\n    Wraps the async job API internally: submit → poll → fetch result.\n    \"\"\"\n\n    def __init__(\n        self,\n        token: Optional[str] = None,\n        base_url: Optional[str] = None,\n        request_timeout: float = 300.0,\n        poll_timeout: float = 600.0,\n        client_platform: Optional[str] = None,\n    ):\n        self._token = token or os.environ.get(\"PADDLEOCR_ACCESS_TOKEN\", \"\")\n        if not self._token:\n            raise AuthError(\n                \"Token is required. Set PADDLEOCR_ACCESS_TOKEN or pass token=.\"\n            )\n        resolved_base_url = (\n            base_url or os.environ.get(\"PADDLEOCR_BASE_URL\") or DEFAULT_BASE_URL\n        )\n        self._http = HTTPClient(\n            self._token,\n            resolved_base_url,\n            request_timeout,\n            client_platform=client_platform,\n        )\n        self._poller = Poller(self._http, max_wait_time=poll_timeout)\n\n    def __enter__(self):\n        return self\n\n    def __exit__(self, *args):\n        self.close()","sourceCodeStart":40,"sourceCodeEnd":76,"githubUrl":"https://github.com/PaddlePaddle/PaddleOCR/blob/2661c7c0ef5c613e8f93c6e93b2e052399f0f854/paddleocr/_api_client/client.py#L40-L76","documentation":"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.","triggerScenarios":"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.","commonSituations":"Local scripts run from an IDE that does not inherit shell env vars; Docker images that drop env vars; CI pipelines missing the secret.","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')))\""],"exampleFix":"# before\nclient = PaddleOCRClient()\n# after\nclient = PaddleOCRClient(token=get_token_from_secret_store())","handlingStrategy":"validation","validationCode":"import os\n\nassert os.environ.get('PADDLEOCR_ACCESS_TOKEN') or TOKEN_FROM_CONFIG, 'PaddleOCR token missing'","typeGuard":null,"tryCatchPattern":"from paddleocr._api_client.errors import AuthError\n\ntry:\n    client = PaddleOCRClient(token=tok)\nexcept AuthError as e:\n    log_and_alert(e)  # config problem, not transient\n    raise","preventionTips":["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"],"tags":["auth","api-client","configuration"],"backgroundTag":null,"analyzedSha":"2661c7c0ef5c613e8f93c6e93b2e052399f0f854","analyzedAt":"2026-08-14T20:17:30.180Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}