md5.hexdigest() converting unicode string to ascii

Krzysztof Stachlewski stach at fr.USUN.pl
Fri Apr 16 18:47:26 EDT 2004


uebertester wrote:

> None of the suggestions seem to address the issue.  sValue =
> _winreg.QueryValueEx(y,"") returns a tuple containing the following
> (u'http://', 1).  The string u'http://' is added to the md5 object via
> the update() and then hashed via hexdigest().  How do I keep the
> unicode string from being converted to ascii with the md5 functions? 

You *have to* convert the unicode string to byte character string
(I'm trying not to call it 'character string' :-) )
md5 needs bytes to work, not unicode characters.
As I have already said, you have some ready-to-use conversions
to choose from. utf8? maybe utf16? I don't know which one you want.
If you don't specify the codec yourself then the ascii codec is used
by default.
Unicode characters are implemented in Python either as 2 or 4 byte integers.
You can't rely on memory representation of those integers (although
you can play with ord() function). You need a codec.

-- 
Stach  Tlen: stachobywatelpl, GG: 1811474
        Jabber: stach at jabber atman pl



More information about the Python-list mailing list