{"id":"af3400f043ce6139","repo":"pika/pika","slug":"credentials-must-be-an-object-of-type-pika-crede","errorCode":null,"errorMessage":"credentials must be an object of type: {pika.credentials.VALID_TYPES!r}, but got {value!r}","messagePattern":"credentials must be an object of type: (.+?), but got (.+?)","errorType":"validation","errorClass":"TypeError","httpStatus":null,"severity":"error","filePath":"pika/connection.py","lineNumber":279,"sourceCode":"        \"\"\"\n        One of the classes from `pika.credentials.VALID_TYPES`.\n\n        Defaults to `DEFAULT_CREDENTIALS`.\n        \"\"\"\n        return self._credentials\n\n    @credentials.setter\n    def credentials(\n        self, value: (pika.credentials.PlainCredentials |\n                      pika.credentials.ExternalCredentials)\n    ) -> None:\n        \"\"\"\n        :param value: authentication credential object of one of the classes\n            from  `pika.credentials.VALID_TYPES`\n\n        \"\"\"\n        if not isinstance(value, tuple(pika.credentials.VALID_TYPES)):\n            raise TypeError(\n                f'credentials must be an object of type: {pika.credentials.VALID_TYPES!r}, but '\n                f'got {value!r}')\n        # Copy the mutable object to avoid accidental side-effects\n        self._credentials = copy.deepcopy(value)\n\n    @property\n    def frame_max(self) -> int:\n        \"\"\"\n        :returns: desired maximum AMQP frame size to use. Defaults to\n            `DEFAULT_FRAME_MAX`.\n\n        \"\"\"\n        return self._frame_max\n\n    @frame_max.setter\n    def frame_max(self, value: int) -> None:\n        \"\"\"\n        :param value: desired maximum AMQP frame size to use between","sourceCodeStart":261,"sourceCodeEnd":297,"githubUrl":"https://github.com/pika/pika/blob/295ad9e5795061d759b694ab1fcb33cd381d8c49/pika/connection.py#L261-L297","documentation":"Raised by Parameters.credentials setter (connection.py:278-281) when value is not an instance of one of pika.credentials.VALID_TYPES (PlainCredentials or ExternalCredentials). pika requires a typed credentials object so it can negotiate the correct SASL auth mechanism; passing a raw tuple, a string, a dict, or None is rejected with TypeError.","triggerScenarios":"Passing a (username, password) tuple directly instead of wrapping it in pika.PlainCredentials; passing a plain password string; passing None; passing a dict like {'username':..., 'password':...}.","commonSituations":"Confusing the credentials object with the raw username/password tuple; migrating from an older config format; loading credentials from a secret store and forgetting to wrap them.","solutions":["Wrap username/password with pika.PlainCredentials(user, password).","For x509 TLS auth, use pika.ExternalCredentials().","Prefer pika.URLParameters('amqp://user:pass@host/vhost') which parses credentials for you."],"exampleFix":"# before\nparams = pika.ConnectionParameters(credentials=('guest', 'guest'))\n\n# after\nimport pika\nparams = pika.ConnectionParameters(\n    credentials=pika.PlainCredentials('guest', 'guest')\n)","handlingStrategy":"type-guard","validationCode":"import pika.credentials\nif not isinstance(value, tuple(pika.credentials.VALID_TYPES)):\n    value = pika.PlainCredentials(value[0], value[1]) if isinstance(value, (tuple, list)) else value\nparams = pika.ConnectionParameters(credentials=value)","typeGuard":"import pika.credentials\n\ndef is_credentials(value) -> bool:\n    return isinstance(value, tuple(pika.credentials.VALID_TYPES))","tryCatchPattern":"try:\n    params = pika.ConnectionParameters(credentials=raw)\nexcept TypeError as e:\n    if 'credentials must be' in str(e):\n        params = pika.ConnectionParameters(credentials=pika.PlainCredentials(raw[0], raw[1]))\n    else:\n        raise","preventionTips":["Wrap username/password with pika.PlainCredentials(user, password).","Use pika.URLParameters for amqp:// URLs to avoid manual credentials construction.","Validate that credential objects come from pika.credentials before assigning."],"tags":["connection-params","credentials","validation","type-error","auth"],"analyzedSha":"295ad9e5795061d759b694ab1fcb33cd381d8c49","analyzedAt":"2026-08-04T20:47:41.389Z","schemaVersion":2}