redis/redis-py · error · DataError

'username' and 'password' cannot be passed along with…

Error message

'username' and 'password' cannot be passed along with 'credential_provider'. Please provide only one of the following arguments: 
1. 'password' and (optional) 'username'
2. 'credential_provider'

What it means

DataError raised at the top of the async Connection constructor (redis/asyncio/connection.py:641) when both (username or password) and credential_provider are supplied. The library cannot decide which credential source to use, so it refuses the ambiguous configuration. Provide exactly one: static credentials, or a credential provider - never both.

Solutions

  1. Remove username/password and keep only credential_provider
  2. Or remove credential_provider and keep username/password
  3. Audit config-merging code that unions both sources

Example fix

// before
Redis(username='u', password='p', credential_provider=provider)
// after
Redis(credential_provider=provider)
Defensive patterns

Strategy: validation

Validate before calling

if (username or password) and credential_provider is not None:
    raise ValueError('pass either username/password or credential_provider, not both')

Prevention

When it happens

Trigger: `Redis(username='u', password='p', credential_provider=MyProvider())`; mixing env-var/default credentials with an explicit provider.

Common situations: Layered config where a base client sets a password and a subclass adds a credential_provider; migrating from static to dynamic credentials and leaving the old fields populated.

Related errors


AI-assisted analysis of redis/redis-py@6a6b581b48 (2026-08-10). Data as JSON: /api/errors/d6563e83043707c2. Report an issue: GitHub.

Appendix: source

Thrown at redis/asyncio/connection.py:642

        ) = None,
        himport_registry: HImportRegistry | None = None,
    ):
        """
        Initialize a new async Connection.

        Parameters
        ----------
        driver_info : DriverInfo, optional
            Driver metadata for CLIENT SETINFO. If provided, lib_name and lib_version
            are ignored. If not provided, a DriverInfo will be created from lib_name
            and lib_version. Explicit None disables CLIENT SETINFO.
        lib_name : str, optional
            **Deprecated.** Use driver_info instead. Library name for CLIENT SETINFO.
        lib_version : str, optional
            **Deprecated.** Use driver_info instead. Library version for CLIENT SETINFO.
        """
        if (username or password) and credential_provider is not None:
            raise DataError(
                "'username' and 'password' cannot be passed along with 'credential_"
                "provider'. Please provide only one of the following arguments: \n"
                "1. 'password' and (optional) 'username'\n"
                "2. 'credential_provider'"
            )
        if event_dispatcher is None:
            self._event_dispatcher = EventDispatcher()
        else:
            self._event_dispatcher = event_dispatcher
        self.db = db
        self.client_name = client_name

        # Handle driver_info: if provided, use it; otherwise create from lib_name/lib_version.
        self.driver_info = resolve_driver_info(driver_info, lib_name, lib_version)

        self.credential_provider = credential_provider
        self.password = password
        self.username = username

View on GitHub (pinned to 6a6b581b48)