Fix TypeError encoding

Fixes: TypeError: Unicode-objects must be encoded before hashing