Python decoding issue with hashlib.digest() method
Posted
by Sorw
on Stack Overflow
See other posts from Stack Overflow
or by Sorw
Published on 2010-03-12T23:56:20Z
Indexed on
2010/03/13
0:17 UTC
Read the original article
Hit count: 548
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 !
© Stack Overflow or respective owner