pola-rs/polars · error · ValueError

unsupported: cannot combine token with

Error message

unsupported: cannot combine token with {unhandled_key} in storage_options

What it means

The auto credential-provider builder scans storage_options for a token; if an unrecognized key (e.g. an access key) is combined with an explicit token it raises, because mixing token-based auth with key-based options in one provider is ambiguous.

Solutions

  1. Remove the extra credential keys, keeping only the token.
  2. Or remove the token and use the service-account/other credentials alone.
  3. Split storage_options per auth strategy instead of merging dicts.

Example fix

// before
 opts = {"token": tok, "google_service_account": sa_path}
// after
 opts = {"token": tok}  # or only google_service_account
Defensive patterns

Strategy: validation

Validate before calling

if 'token' in opts and len(opts) > 1:
    raise ValueError('token cannot be combined with other credential keys in storage_options')

Type guard

def token_only(opts: dict) -> dict:
    if 'token' in opts and set(opts) != {'token'}:
        return {'token': opts['token']}
    return opts

Try / catch

try:
    lf = pl.scan_parquet(url, storage_options=opts)
except ValueError as e:
    if 'cannot combine token' in str(e):
        opts = {'token': opts['token']}
        lf = pl.scan_parquet(url, storage_options=opts)
    else:
        raise

Prevention

When it happens

Trigger: Passing storage_options containing {'token': '<gcp-token>'} together with other credential keys (e.g. google_service_account, service-account key JSON, aws keys) when a credential provider is being built.

Common situations: Merging storage_options from multiple sources where one adds a token and another adds service-account credentials; switching from service-account auth to token auth without cleaning old keys.

Related errors


AI-assisted analysis of pola-rs/polars@fe841f959e (2026-09-18). Data as JSON: /api/errors/b5aa70beeeba9589. Report an issue: GitHub.

Appendix: source

Thrown at py-polars/src/polars/io/cloud/credential_provider/_builder.py:526

                    k = k.lower()

                    # https://docs.rs/object_store/latest/object_store/gcp/enum.GoogleConfigKey.html
                    if k in {"token", "bearer_token"}:
                        token = v
                    elif k in AUTOINIT_IGNORED_KEYS:
                        continue
                    else:
                        # We assume some sort of access key was given, so we
                        # just dispatch to the rust side.
                        unhandled_key = k

            if unhandled_key is not None:
                if token is not None:
                    msg = (
                        "unsupported: cannot combine token with "
                        f"{unhandled_key} in storage_options"
                    )
                    raise ValueError(msg)

                return None

            if token is not None:
                return CredentialProviderBuilder(
                    InitializedCredentialProvider(UserProvidedGCPToken(token))
                )

            if (default := get_default_credential_provider()) is not None:
                return default

            return CredentialProviderBuilder(AutoInit(CredentialProviderGCP))

        return None

    credential_provider_init = f()

    if verbose():

View on GitHub (pinned to fe841f959e)