redis/redis-py · error · DataError
'username' and 'password' cannot be passed along with 'crede
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
Raised as DataError in Connection.__init__ when both (username or password) and credential_provider are supplied. The library cannot decide which credential source to use, so it refuses to construct the connection rather than silently preferring one. Pick exactly one authentication strategy.
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 = usernameView on GitHub (pinned to da03cdc7e8)
Solutions
- Provide only the credential_provider when using dynamic credentials (drop username/password).
- Or provide only username/password when using static credentials (drop credential_provider).
- Audit config-merging code (e.g. from_url + kwargs, settings dicts) to ensure the two auth strategies are not both present.
Example fix
// before
client = Redis(
username='u', password='p',
credential_provider=EntraIDProvider(), # raises [94]
)
// after
client = Redis(credential_provider=EntraIDProvider()) 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') Try / catch
from redis.exceptions import DataError
try:
client = Redis(password=p, credential_provider=cp)
except DataError as e:
if 'cannot be passed along with' in str(e):
client = Redis(credential_provider=cp) # drop static creds Prevention
- Pick one auth strategy; never pass both static creds and a provider.
- Audit config-merging layers (env + code) for double auth.
When it happens
Trigger: Constructing Redis(..., password='x', credential_provider=MyProvider()) or Connection(username='u', password='p', credential_provider=...) — passing both static credentials and a provider in the same call.
Common situations: Migrating from static credentials to a credential provider (EntraID/JWT) and forgetting to remove the old password kwarg; layering config from multiple sources (env vars + code) that both set auth.
Related errors
- protocol must be an integer
- protocol must be either 2 or 3
- Invalid Username or Password
- Maintenance notifications are only supported with hiredis an
- Invalid Database
AI-assisted analysis of redis/redis-py@da03cdc7e8 (2026-08-04).
Data as JSON: /data/errors/d6563e83043707c2.json.
Report an issue: GitHub.