{"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/da03cdc7e8731092b13e395605c3c1fb2de25de1/redis/connection.py#L849-L885","documentation":"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.","triggerScenarios":"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__.","commonSituations":"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.","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."],"exampleFix":"// before\nr = redis.Redis(host=h, password='secret', credential_provider=provider)\n// after\nr = redis.Redis(host=h, credential_provider=provider)","handlingStrategy":"validation","validationCode":"def build_client(host, password=None, credential_provider=None, **kw):\n    if (password) and credential_provider is not None:\n        raise ValueError('Pass password OR credential_provider, not both')\n    return redis.Redis(host=host, password=password, credential_provider=credential_provider, **kw)","typeGuard":null,"tryCatchPattern":"from redis.exceptions import DataError\ntry:\n    r = redis.Redis(host=h, password=p, credential_provider=prov)\nexcept DataError as e:\n    # remove one auth source and retry\n    pass","preventionTips":["Treat username/password and credential_provider as mutually exclusive in config loaders.","Unit-test client construction to catch mutually-exclusive auth args early."],"tags":["authentication","configuration","credential-provider"],"analyzedSha":"da03cdc7e8731092b13e395605c3c1fb2de25de1","analyzedAt":"2026-08-04T20:26:47.563Z","schemaVersion":2}