Python 3 string to hex October 10, 2023 by Tarik The hex codec has been chucked in 3.x. Use binascii instead: >>> binascii.hexlify(b'hello') b'68656c6c6f'