Why is the encode() needed? hex should already return a suitable string.