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 a DataError in the Connection constructor when both static credentials (username/password) and a credential_provider are supplied. These are mutually exclusive auth mechanisms: the library cannot decide which to use, so it refuses to construct the connection. Provide exactly one of the two strategies.
Source
Thrown at redis/connection.py:867
To specify a retry policy for specific errors, first set
`retry_on_error` to a list of the error/s to retry on, then set
`retry` to a valid `Retry` object.
To retry on TimeoutError, `retry_on_timeout` can also be set to `True`.
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.pid = os.getpid()
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 = passwordView on GitHub (pinned to da03cdc7e8)
Solutions
- Remove username/password kwargs when using credential_provider.
- If you intended static auth, drop the credential_provider kwarg.
- Audit config loaders / env-var mapping so only one auth source is active.
Example fix
// before r = redis.Redis(host=h, password='secret', credential_provider=provider) // after r = redis.Redis(host=h, credential_provider=provider)
Defensive patterns
Strategy: validation
Validate before calling
def build_client(host, password=None, credential_provider=None, **kw):
if (password) and credential_provider is not None:
raise ValueError('Pass password OR credential_provider, not both')
return redis.Redis(host=host, password=password, credential_provider=credential_provider, **kw) Try / catch
from redis.exceptions import DataError
try:
r = redis.Redis(host=h, password=p, credential_provider=prov)
except DataError as e:
# remove one auth source and retry
pass Prevention
- Treat username/password and credential_provider as mutually exclusive in config loaders.
- Unit-test client construction to catch mutually-exclusive auth args early.
When it happens
Trigger: Constructing redis.Redis(..., password='x', credential_provider=provider) or redis.Redis(..., username='u', password='p', credential_provider=provider). Passing a credential_provider (e.g. for EntraID/JWT/token auth) alongside any username/password triggers the check at the top of __init__.
Common situations: Migrating from static password auth to a credential provider but forgetting to remove the old password kwarg; copy-pasting config that sets both; environment variables populating password while code also injects a provider.
Related errors
- Maintenance notifications handlers on connection are only su
- Argument 'db' must be 0 or None in cluster mode
- Unix domain socket is not supported in cluster mode
- RedisCluster requires at least one node to discover the clus
- Maintenance notifications are only supported with RESP versi
AI-assisted analysis of redis/redis-py@da03cdc7e8 (2026-08-04).
Data as JSON: /data/errors/d1eeace91fb398c8.json.
Report an issue: GitHub.