{"record":{"id":"80bfc2c655c05357","repo":"PaddlePaddle/PaddleOCR","slug":"authentication-failed-msg","errorCode":null,"errorMessage":"Authentication failed: {msg}","messagePattern":"Authentication failed: (.+?)","errorType":"exception","errorClass":"AuthError","httpStatus":401,"severity":"critical","filePath":"paddleocr/_api_client/_core.py","lineNumber":152,"sourceCode":"            total_pages=ep.get(\"totalPages\", 0),\n            extracted_pages=ep.get(\"extractedPages\", 0),\n            start_time=ep.get(\"startTime\"),\n            end_time=ep.get(\"endTime\"),\n        )\n    return JobStatus(\n        job_id=job_id,\n        state=state,\n        progress=progress,\n        result=data.get(\"resultUrl\"),\n        error_msg=data.get(\"errorMsg\"),\n    )\n\n\ndef raise_for_status(status_code: int, msg: str) -> None:\n    if 200 <= status_code < 300:\n        return\n    if status_code in (401, 403):\n        raise AuthError(f\"Authentication failed: {msg}\")\n    if status_code == 400:\n        raise InvalidRequestError(f\"Bad request: {msg}\")\n    if status_code == 429:\n        raise RateLimitError(f\"Rate limit exceeded: {msg}\")\n    if status_code in (503, 504):\n        raise ServiceUnavailableError(status_code, f\"Service unavailable: {msg}\")\n    raise APIError(status_code, msg)\n\n\ndef unwrap_api_response(payload: dict, status_code: int) -> dict:\n    if not isinstance(payload, dict):\n        raise ResponseFormatError(\"Response body must be a JSON object.\")\n    code = payload.get(\"code\", 0)\n    if code not in (0, None):\n        raise APIError(status_code, extract_api_message_from_payload(payload) or \"\")\n    data = payload.get(\"data\")\n    if not isinstance(data, dict):\n        raise ResponseFormatError(\"Response JSON must contain object field 'data'.\")","sourceCodeStart":134,"sourceCodeEnd":170,"githubUrl":"https://github.com/PaddlePaddle/PaddleOCR/blob/2661c7c0ef5c613e8f93c6e93b2e052399f0f854/paddleocr/_api_client/_core.py#L134-L170","documentation":"Raised as AuthError by raise_for_status() when the HTTP response status is 401 or 403. The message embeds the API-provided text. It means the API key is missing, invalid, expired, or lacks permission for the requested resource.","triggerScenarios":"Any HTTP call (job creation, status, result fetch, file upload) returning 401/403: bad apikey, key from a different environment, revoked token, or accessing another account's resource id.","commonSituations":"API key typo or copied with whitespace/newline, expired AI Studio token, key valid in dev but not prod, or environment variable not set so an empty key is sent.","solutions":["Verify the API key is set and was copied exactly (no surrounding whitespace).","Confirm the key is still active and has access to the model/endpoint being called.","Check you are pointing at the correct environment/base URL for that key.","Regenerate the key if compromised or revoked, then update your environment/config."],"exampleFix":"# before\nclient = PaddleOCRClient(apikey=os.environ.get(\"PADDLE_API_KEY\"))  # may be None/empty\n\n# after\nkey = os.environ[\"PADDLE_API_KEY\"].strip()\nassert key, \"PADDLE_API_KEY must be set\"\nclient = PaddleOCRClient(apikey=key)","handlingStrategy":"validation","validationCode":"key = (os.environ.get(\"PADDLE_API_KEY\") or \"\").strip()\nif not key:\n    raise RuntimeError(\"PADDLE_API_KEY is not set\")\nclient = PaddleOCRClient(apikey=key)","typeGuard":null,"tryCatchPattern":"from paddleocr._api_client.errors import AuthError\ntry:\n    result = await client.ocr(file_path=p)\nexcept AuthError:\n    alert(\"credentials rejected; halting batch\")\n    raise  # do not retry with the same key","preventionTips":["Strip and assert the API key at startup before any call.","Never retry AuthError automatically; fix the credential first.","Keep separate keys per environment and verify which one is deployed."],"tags":["auth","http","api-key"],"backgroundTag":null,"analyzedSha":"2661c7c0ef5c613e8f93c6e93b2e052399f0f854","analyzedAt":"2026-08-14T20:17:30.180Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}