Python decoding issue with hashlib.digest() method
Hello StackOverflow community,
Using Google App Engine, I wrote a keyToSha256() method within a model class (extending db.Model) :
class Car(db.Model):
def keyToSha256(self):
keyhash = hashlib.sha256(str(self.key())).digest()
开发者_高级运维 return keyhash
When displaying the output (ultimately within a Django template), I get garbled text, for example :
�����_ɘ�!`�I�!�;�QeqN��Al�'2
I was expecting something more in line with this :
9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08
Am I missing something important ? Despite reading several guides on ASCII, Unicode, utf-8 and the like, I think I'm still far from mastering the secrets of string encoding/decoding. After browsing StackOverflow and searching for insights via Google, I figured out I should ask the question here. Any idea ? Thanks !
Use .hexdigest()
instead.
精彩评论