pika/pika · error · TypeError
credentials must be an object of type: {pika.credentials.VAL
Error message
credentials must be an object of type: {pika.credentials.VALID_TYPES!r}, but got {value!r} What it means
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.
Source
Thrown at pika/connection.py:279
"""
One of the classes from `pika.credentials.VALID_TYPES`.
Defaults to `DEFAULT_CREDENTIALS`.
"""
return self._credentials
@credentials.setter
def credentials(
self, value: (pika.credentials.PlainCredentials |
pika.credentials.ExternalCredentials)
) -> None:
"""
:param value: authentication credential object of one of the classes
from `pika.credentials.VALID_TYPES`
"""
if not isinstance(value, tuple(pika.credentials.VALID_TYPES)):
raise TypeError(
f'credentials must be an object of type: {pika.credentials.VALID_TYPES!r}, but '
f'got {value!r}')
# Copy the mutable object to avoid accidental side-effects
self._credentials = copy.deepcopy(value)
@property
def frame_max(self) -> int:
"""
:returns: desired maximum AMQP frame size to use. Defaults to
`DEFAULT_FRAME_MAX`.
"""
return self._frame_max
@frame_max.setter
def frame_max(self, value: int) -> None:
"""
:param value: desired maximum AMQP frame size to use betweenView on GitHub (pinned to 295ad9e579)
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.
Example fix
# before
params = pika.ConnectionParameters(credentials=('guest', 'guest'))
# after
import pika
params = pika.ConnectionParameters(
credentials=pika.PlainCredentials('guest', 'guest')
) Defensive patterns
Strategy: type-guard
Validate before calling
import pika.credentials
if not isinstance(value, tuple(pika.credentials.VALID_TYPES)):
value = pika.PlainCredentials(value[0], value[1]) if isinstance(value, (tuple, list)) else value
params = pika.ConnectionParameters(credentials=value) Type guard
import pika.credentials
def is_credentials(value) -> bool:
return isinstance(value, tuple(pika.credentials.VALID_TYPES)) Try / catch
try:
params = pika.ConnectionParameters(credentials=raw)
except TypeError as e:
if 'credentials must be' in str(e):
params = pika.ConnectionParameters(credentials=pika.PlainCredentials(raw[0], raw[1]))
else:
raise Prevention
- 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.
When it happens
Trigger: 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':...}.
Common situations: 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.
Related errors
- Expected pika.connection.Parameters instance, but got None i
- connection_configs does not support iteration: {error!r}
- blocked_connection_timeout must be a Real number, but got {v
- channel_max must be an int, but got {value!r}
- client_properties must be dict or None, but got {value!r}
AI-assisted analysis of pika/pika@295ad9e579 (2026-08-04).
Data as JSON: /data/errors/af3400f043ce6139.json.
Report an issue: GitHub.