[Tutor] str() conversion of unicode?

Tod Haren ke7fxl at gmail.com
Fri Nov 17 20:52:06 CET 2006

I'm trying to calculate md5's on records from a Paradox database.  The
problem is that apparently some of the records have non ASCII
characters.  I'm at a loss as to how I should handle this.

This snippet is called for each row in my recordset:

m = md5.new()
for f in rs.fields.keys():
    val = str(rs.fields[f].value)
m = m.hexdigest()

the str() convertion throws this error:
UnicodeEncodeError: 'ascii' codec can't encode character u'\xbd' in
position 1: ordinal not in range(128)

print u'\xbd' renders the '1/2' symbol.  I would eliminate the str()
but md5 barks when you pass anything but a string apparently.  Is
there another way to coerce the field values to a string?

More information about the Tutor mailing list