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
Raised in AbstractConnection.__init__ (connection.py:866-872) when both (username or password) and credential_provider are passed. The library accepts exactly one auth source — static credentials OR a credential_provider (e.g. for rotating tokens like EntraID) — because mixing them is ambiguous. Passing both is treated as a programming error and rejected up front as a DataError.
Solutions
- Remove the username/password arguments and keep only credential_provider.
- Or remove the credential_provider and keep username/password.
- If using env-based static creds, do not also pass a provider — pick one auth source in your config loader.
- Audit your connection factory / config dict so exactly one auth branch is populated.
Example fix
# before
r = redis.Redis(
username='u', password='p',
credential_provider=UsernamePasswordCredentialProvider('u','p'),
)
# after
r = redis.Redis(credential_provider=UsernamePasswordCredentialProvider('u','p')) Defensive patterns
Strategy: validation
Validate before calling
# Pick exactly one auth source before constructing the client
has_static = bool(username or password)
has_provider = credential_provider is not None
assert not (has_static and has_provider), (
'supply either (username,password) OR credential_provider, not both'
)
r = redis.Redis(host=h, port=p,
credential_provider=credential_provider if has_provider else None,
username=username if not has_provider else None,
password=password if not has_provider else None) Type guard
null
Try / catch
from redis.exceptions import DataError
try:
r = redis.Redis(host=h, port=p, username=u, password=pw, credential_provider=prov)
except DataError as e:
if 'credential_provider' in str(e):
# keep the provider, drop static creds
r = redis.Redis(host=h, port=p, credential_provider=prov)
else:
raise Prevention
- Centralise auth construction in one factory so both branches can't be set together.
- Treat credential_provider as mutually exclusive with static creds in config schemas.
- Validate config dicts at load time.
When it happens
Trigger: Calling redis.Redis(username=..., password=..., credential_provider=UsernamePasswordCredentialProvider(...)) or any Connection/ConnectionPool constructor that supplies both a static password/username and a credential_provider object.
Common situations: Migrating from static passwords to a credential provider and forgetting to remove the old password kwarg; loading credentials from a config file that sets REDIS_PASSWORD while also wiring up a provider; copy-pasting an example that included both.
Related errors
- Cache must implement CacheInterface
- Error setting client name
- Invalid Database
- Invalid SSL Certificate Requirements Flag
- Invalid ssl verify flag
AI-assisted analysis of redis/redis-py@6a6b581b48 (2026-08-10).
Data as JSON: /api/errors/d1eeace91fb398c8.
Report an issue: GitHub.
Appendix: 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 6a6b581b48)