How to use the ‘hex’ encoding in Python 3.2 or higher?
You need to go via the codecs module and the hex_codec codec (or its hex alias if available*): codecs.encode(b’\x12′, ‘hex_codec’) * From the documentation: “Changed in version 3.4: Restoration of the aliases for the binary transforms”.