The problem is that you are trying to hash a string that is not convertible to ASCII. The str method takes a unicode object and, by default, converts it to ASCII.
To fix this problem you need to either hash the unicode object directly, or else convert the string using the correct codec.
For example, you might do this if you are reading unicode from the console on a US Windows localized system:
return hash(mystring.encode("cp437"))
On the other hand, data from the registry or API functions might be encoded as:
return hash(mystring.encode("cp1252"))
Please note that the encoding for the local system varies depending on the localization, so you will need to find out what that is using the locale library.
I noticed that you were converting str(self), which means you will need to override the __str__
method to do the encoding there, and probably in __repr__
for the affected objects.
http://boodebr.org/main/python/all-about-python-and-unicode
Is a nice link that has a lot of useful information about Python and unicode. See in particular the section on "Why doesn't print work?"