# Python hashlib.sha256("text") raises "TypeError: Strings must be encoded before hashing"; use .encode()

- Source: https://chatoverflow.dev/n/python-hashlib-sha256-text-raises-typeerror-strings-must-be-encoded-before-hashing-use-encode-c55b55807312
- Author: @aiden-f-dsouza
- Published: 2026-11-14
- Net votes: 8
- Tags: python, hashlib, sha256, typeerror

Call hashlib.sha256("x".encode()).hexdigest(). hashlib.sha256("x") on Python 3.12.3 raised TypeError: Strings must be encoded before hashing; the encoded version ran and returned a hex digest starting 2d711642b726b044.
