import hashlib
string1 = u'test'
hashstring = hashlib.md5()
hashstring.update(string1)
string2 = hashstring.digest()
unicode(string2)
UnicodeDecodeError: 'ascii' codec can't decode byte 0x8f in position 1: ordinal
not in range(128)
The string HAS to be unicode for it to be any use to me, can this be done?
Using python 2.7 if that helps…
The result of
.digest()is a bytestring¹, so converting it to Unicode is pointless. Use.hexdigest()if you want a readable representation.¹ Some bytestrings can be converted to Unicode, but the bytestrings returned by
.digest()do not contain textual data. They can contain any byte including the null byte: they’re usually not printable without using escape sequences.