[Tutor] Unicode Encode Error

Frank Moore francis.moore at rawflow.com
Thu Apr 27 15:01:05 CEST 2006


I'm getting the following error when I try and write some HTML with 
German text in it.

UnicodeEncodeError: 'ascii' codec can't encode character u'\xf6' in 
position 1367: ordinal not in range(128)

This was my code:

      html_text = open(inFile, 'r').read()
     # ... do some processing on html_text
      file(outFile, 'w').write(html_text)

I've now read the 'Unicode - How To' by AMKuchling and changed the code to:

      html_text = codecs.open(inFile, encoding='utf-8').read()
     # ... do some processing on html_text
      f = codecs.open(outFile, encoding='utf-8', mode='w')

but I'm still getting the error.
Does anybody know what I'm doing wrong?


More information about the Tutor mailing list