{"record":{"id":"77fef9159caccc1d","repo":"pola-rs/polars","slug":"the-provided-credential-object-credential-r-do","errorCode":null,"errorMessage":"the provided `credential` object {credential!r} does not have a `get_token()` method.","messagePattern":"the provided `credential` object (.+?) does not have a `get_token\\(\\)` method\\.","errorType":"exception","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"py-polars/src/polars/io/cloud/credential_provider/_providers.py","lineNumber":379,"sourceCode":"        msg = \"`CredentialProviderAzure` functionality is considered unstable\"\n        issue_unstable_warning(msg)\n\n        self.account_name = _storage_account\n        self.scopes = (\n            scopes if scopes is not None else [\"https://storage.azure.com/.default\"]\n        )\n        self.tenant_id = tenant_id\n        self.credential = credential\n\n        if credential is not None:\n            # If the user passes a credential class, we just need to ensure it\n            # has a `get_token()` method.\n            if not hasattr(credential, \"get_token\"):\n                msg = (\n                    f\"the provided `credential` object {credential!r} does \"\n                    \"not have a `get_token()` method.\"\n                )\n                raise ValueError(msg)\n\n        # We don't need the module if we are permitted and able to retrieve the\n        # account key from the Azure CLI.\n        elif self._try_get_azure_storage_account_credential_if_permitted() is None:\n            self._ensure_module_availability()\n\n        if verbose():\n            eprint(\n                \"[CredentialProviderAzure]: \"\n                f\"{self.account_name = } \"\n                f\"{self.tenant_id = } \"\n                f\"{self.scopes = } \"\n            )\n\n        super().__init__()\n\n    def retrieve_credentials_impl(self) -> CredentialProviderFunctionReturn:\n        \"\"\"Fetch the credentials.\"\"\"","sourceCodeStart":361,"sourceCodeEnd":397,"githubUrl":"https://github.com/pola-rs/polars/blob/fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e/py-polars/src/polars/io/cloud/credential_provider/_providers.py#L361-L397","documentation":"CredentialProviderAzure's constructor accepts a `credential` object that must expose get_token() (an azure-identity TokenCredential). Passing an object without that method raises ValueError, and if no Azure storage account key can be retrieved instead, the azure-identity module availability is then enforced.","triggerScenarios":"Passing credential=<obj> where obj lacks get_token — e.g. a raw client secret string, a service-principal dict, a boto3-style credentials object, or a custom class without get_token.","commonSituations":"Confusing Azure account keys/Connection strings with TokenCredential objects; passing ClientSecretCredential wrapped or misconstructed; wiring AWS credentials into an Azure provider by mistake.","solutions":["Pass an azure-identity TokenCredential, e.g. azure.identity.ClientSecretCredential(tenant_id, client_id, client_secret).","If you have a connection string/account key, use the account-key path instead of the credential argument.","Add a get_token() method conforming to the TokenCredential protocol if using a custom credential."],"exampleFix":"// before\n provider = pl.CredentialProviderAzure(credential={\"tenantId\": t, \"clientId\": c, \"clientSecret\": s})\n// after\n from azure.identity import ClientSecretCredential\n provider = pl.CredentialProviderAzure(credential=ClientSecretCredential(t, c, s))","handlingStrategy":"type-guard","validationCode":"cred = ...  # user-supplied\nif cred is not None and not callable(getattr(cred, 'get_token', None)):\n    raise TypeError('credential must implement get_token() (azure-identity TokenCredential)')","typeGuard":"from typing import Any, Protocol\n\nclass TokenCredential(Protocol):\n    def get_token(self, *scopes: str, **kwargs: Any) -> Any: ...\n\ndef is_token_credential(obj: Any) -> bool:\n    return callable(getattr(obj, 'get_token', None))","tryCatchPattern":"try:\n    provider = pl.CredentialProviderAzure(credential=cred)\nexcept ValueError as e:\n    if 'get_token()' in str(e):\n        from azure.identity import DefaultAzureCredential\n        provider = pl.CredentialProviderAzure(credential=DefaultAzureCredential())\n    else:\n        raise","preventionTips":["Only pass azure-identity TokenCredential instances (ClientSecretCredential, DefaultAzureCredential, etc.).","Never pass strings, dicts, or connection strings as `credential` — use the account-key path for those.","Type-annotate the credential parameter as TokenCredential in your wrappers."],"tags":["python","azure","credentials","type-mismatch"],"backgroundTag":"invalid-argument-value","analyzedSha":"fe841f959ef4d2ceefc05a310d33ed7b1ab24e5e","analyzedAt":"2026-09-18T22:14:11.667Z","contentChangedAt":"2026-09-18T22:14:11.667Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}