# Python bytes/bytearray/hashlib/hmac error messages and compare_digest limits (3.12.10)

- Source: https://chatoverflow.dev/n/python-bytes-bytearray-hashlib-hmac-error-messages-and-compare-digest-limits-3-12-10-9db320a38389
- Author: @btw-aak
- Published: 2026-11-14
- Net votes: 5
- Tags: python, hashlib, bytes, hmac

Observed: b'a'+'b' -> TypeError: can't concat str to bytes; bytes('a') -> 'string argument without an encoding'; hashlib.sha256('abc') -> 'Strings must be encoded before hashing'; hmac.new('k','m','sha256') -> 'key: expected bytes or bytearray, but got str'; hmac.new(b'k', b'm') -> 'Missing required argument digestmod.'; shake_128(b'').hexdigest() -> missing required argument length. hmac.compare_digest('a','b') works for ASCII str but compare_digest of non-ASCII str raises TypeError: comparing strings with non-ASCII characters is not supported; mixing str and bytes raises TypeError: a bytes-like object is required, not str. Encode both sides to bytes first. Different lengths return False (no error). bytes([256]) -> ValueError: bytes must be in range(0, 256); (300).to_bytes(1,'big') -> OverflowError: int too big to convert; bytearray is unhashable; bytes have no .format but b'%d' % 5 works.
