{"record":{"id":"3316cc9b79a21d1f","repo":"infiniflow/ragflow","slug":"invalid-or-expired-google-drive-credentials-401","errorCode":null,"errorMessage":"Invalid or expired Google Drive credentials (401).","messagePattern":"Invalid or expired Google Drive credentials \\(401\\)\\.","errorType":"validation","errorClass":"CredentialExpiredError","httpStatus":401,"severity":"error","filePath":"common/data_source/google_drive/connector.py","lineNumber":1133,"sourceCode":"        if self._creds is None:\n            raise ConnectorMissingCredentialError(\"Google Drive credentials not loaded.\")\n\n        if self._primary_admin_email is None:\n            raise ConnectorValidationError(\"Primary admin email not found in credentials. Ensure DB_CREDENTIALS_PRIMARY_ADMIN_KEY is set.\")\n\n        try:\n            drive_service = get_drive_service(self._creds, self._primary_admin_email)\n            drive_service.files().list(pageSize=1, fields=\"files(id)\").execute()\n\n            if isinstance(self._creds, ServiceAccountCredentials):\n                # default is ~17mins of retries, don't do that here since this is called from\n                # the UI\n                get_root_folder_id(drive_service)\n\n        except HttpError as e:\n            status_code = e.resp.status if e.resp else None\n            if status_code == 401:\n                raise CredentialExpiredError(\"Invalid or expired Google Drive credentials (401).\")\n            elif status_code == 403:\n                raise InsufficientPermissionsError(\"Google Drive app lacks required permissions (403). Please ensure the necessary scopes are granted and Drive apps are enabled.\")\n            else:\n                raise ConnectorValidationError(f\"Unexpected Google Drive error (status={status_code}): {e}\")\n\n        except Exception as e:\n            # Check for scope-related hints from the error message\n            if MISSING_SCOPES_ERROR_STR in str(e):\n                raise InsufficientPermissionsError(\"Google Drive credentials are missing required scopes.\")\n            raise ConnectorValidationError(f\"Unexpected error during Google Drive validation: {e}\")\n\n    @override\n    def build_dummy_checkpoint(self) -> GoogleDriveCheckpoint:\n        return GoogleDriveCheckpoint(\n            retrieved_folder_and_drive_ids=set(),\n            completion_stage=DriveRetrievalStage.START,\n            completion_map=ThreadSafeDict(),\n            all_retrieved_file_ids=set(),","sourceCodeStart":1115,"sourceCodeEnd":1151,"githubUrl":"https://github.com/infiniflow/ragflow/blob/554fb1133ac3861732235ad9c377eb5e0a770665/common/data_source/google_drive/connector.py#L1115-L1151","documentation":"Error \"Invalid or expired Google Drive credentials (401).\" thrown in infiniflow/ragflow.","triggerScenarios":"Thrown at common/data_source/google_drive/connector.py:1133 when the library encounters an invalid state.","commonSituations":"Google Drive returns 401 because the access/refresh token is expired or revoked; re-authorizing prevents this error.","solutions":["Refresh or re-authorize the Google Drive credentials.","Verify the token has not been revoked in Google admin console."],"exampleFix":"# re-run the OAuth consent flow to mint fresh tokens","handlingStrategy":null,"validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"554fb1133ac3861732235ad9c377eb5e0a770665","analyzedAt":"2026-08-15T09:20:16.380Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}