This is in python 2.4. Here is my situation. I pull the row from the database and it contains umlauted 'o' (\ xf6). At this point, if I run the type (value), it will return str. Then I try to run .decode ('utf-8') and I get an error message ('utf8' codec cannot decode bytes at positions 1-4).
Indeed my goal here is simply to successfully make the type (value) return unicode. I found an earlier question that had some useful information, but the example from the selected answer does not seem to work for me. Am I doing something wrong here?
Here is the code to play:
Name = 'w\xc3\xb6rner'.decode('utf-8')
file.write('Name: %s - %s\n' %(Name, type(Name)))
I never get a write statement because it does not work in the first expression.
Thank you for your help.
Edit:
I checked that the DB encoding is utf8. So in my code for playback, I changed '\ xf6' to '\ xc3 \ xb6' and the error still occurs. Is there a difference between utf-8 and utf8?
The advice on using codecs to write to a file is convenient (I will definitely use it), but in this scenario I only write to the log file for debugging purposes.
source
share