{"record":{"id":"d1eeace91fb398c8","repo":"redis/redis-py","slug":"username-and-password-cannot-be-passed-along-w-d1eeac","errorCode":null,"errorMessage":"'username' and 'password' cannot be passed along with 'credential_provider'. Please provide only one of the following arguments: \n1. 'password' and (optional) 'username'\n2. 'credential_provider'","messagePattern":"'username' and 'password' cannot be passed along with 'credential_provider'\\. Please provide only one of the following arguments: \n1\\. 'password' and \\(optional\\) 'username'\n2\\. 'credential_provider'","errorType":"validation","errorClass":"DataError","httpStatus":null,"severity":"error","filePath":"redis/connection.py","lineNumber":867,"sourceCode":"\n        To specify a retry policy for specific errors, first set\n        `retry_on_error` to a list of the error/s to retry on, then set\n        `retry` to a valid `Retry` object.\n        To retry on TimeoutError, `retry_on_timeout` can also be set to `True`.\n\n        Parameters\n        ----------\n        driver_info : DriverInfo, optional\n            Driver metadata for CLIENT SETINFO. If provided, lib_name and lib_version\n            are ignored. If not provided, a DriverInfo will be created from lib_name\n            and lib_version. Explicit None disables CLIENT SETINFO.\n        lib_name : str, optional\n            **Deprecated.** Use driver_info instead. Library name for CLIENT SETINFO.\n        lib_version : str, optional\n            **Deprecated.** Use driver_info instead. Library version for CLIENT SETINFO.\n        \"\"\"\n        if (username or password) and credential_provider is not None:\n            raise DataError(\n                \"'username' and 'password' cannot be passed along with 'credential_\"\n                \"provider'. Please provide only one of the following arguments: \\n\"\n                \"1. 'password' and (optional) 'username'\\n\"\n                \"2. 'credential_provider'\"\n            )\n        if event_dispatcher is None:\n            self._event_dispatcher = EventDispatcher()\n        else:\n            self._event_dispatcher = event_dispatcher\n        self.pid = os.getpid()\n        self.db = db\n        self.client_name = client_name\n\n        # Handle driver_info: if provided, use it; otherwise create from lib_name/lib_version.\n        self.driver_info = resolve_driver_info(driver_info, lib_name, lib_version)\n\n        self.credential_provider = credential_provider\n        self.password = password","sourceCodeStart":849,"sourceCodeEnd":885,"githubUrl":"https://github.com/redis/redis-py/blob/6a6b581b48225afa0b76912d1028c6035baee932/redis/connection.py#L849-L885","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"# before\nr = redis.Redis(\n    username='u', password='p',\n    credential_provider=UsernamePasswordCredentialProvider('u','p'),\n)\n# after\nr = redis.Redis(credential_provider=UsernamePasswordCredentialProvider('u','p'))","handlingStrategy":"validation","validationCode":"# Pick exactly one auth source before constructing the client\nhas_static = bool(username or password)\nhas_provider = credential_provider is not None\nassert not (has_static and has_provider), (\n    'supply either (username,password) OR credential_provider, not both'\n)\nr = redis.Redis(host=h, port=p,\n                credential_provider=credential_provider if has_provider else None,\n                username=username if not has_provider else None,\n                password=password if not has_provider else None)","typeGuard":"null","tryCatchPattern":"from redis.exceptions import DataError\ntry:\n    r = redis.Redis(host=h, port=p, username=u, password=pw, credential_provider=prov)\nexcept DataError as e:\n    if 'credential_provider' in str(e):\n        # keep the provider, drop static creds\n        r = redis.Redis(host=h, port=p, credential_provider=prov)\n    else:\n        raise","preventionTips":["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."],"tags":["authentication","configuration","credential-provider","validation"],"backgroundTag":null,"analyzedSha":"6a6b581b48225afa0b76912d1028c6035baee932","analyzedAt":"2026-08-10T12:52:44.840Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-21T04:17:39.646Z"}