{"id":"d6563e83043707c2","repo":"redis/redis-py","slug":"username-and-password-cannot-be-passed-along-w","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/asyncio/connection.py","lineNumber":642,"sourceCode":"        ) = None,\n        himport_registry: HImportRegistry | None = None,\n    ):\n        \"\"\"\n        Initialize a new async Connection.\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.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\n        self.username = username","sourceCodeStart":624,"sourceCodeEnd":660,"githubUrl":"https://github.com/redis/redis-py/blob/da03cdc7e8731092b13e395605c3c1fb2de25de1/redis/asyncio/connection.py#L624-L660","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nclient = Redis(\n    username='u', password='p',\n    credential_provider=EntraIDProvider(),  # raises [94]\n)\n// after\nclient = Redis(credential_provider=EntraIDProvider())","handlingStrategy":"validation","validationCode":"if (username or password) and credential_provider is not None:\n    raise ValueError('Pass either username/password OR credential_provider, not both')","typeGuard":null,"tryCatchPattern":"from redis.exceptions import DataError\ntry:\n    client = Redis(password=p, credential_provider=cp)\nexcept DataError as e:\n    if 'cannot be passed along with' in str(e):\n        client = Redis(credential_provider=cp)  # drop static creds","preventionTips":["Pick one auth strategy; never pass both static creds and a provider.","Audit config-merging layers (env + code) for double auth."],"tags":["connection","auth","credentials","config","validation"],"analyzedSha":"da03cdc7e8731092b13e395605c3c1fb2de25de1","analyzedAt":"2026-08-04T20:26:47.563Z","schemaVersion":2}