Novice blues with UTF-8, Expat and Python

Henri De Feraudy <[email protected]>
Newsgroups gmane.text.xml.expat.general
Message-ID <[email protected]>
Hi folks, 
    I've been trying to parse an XML file that contained some French accented characters and the program raised an error. Although you may have a quick answer,
  may I suggest that an example in the Python Expat documentation could have avoided my taking up your time.
   
  Here's the script:
  import codecs
from xml.parsers.expat import ParserCreate
  ifh = codecs.open("FrenchText.xml","r","utf-8")
text = ifh.read()
ifh.close()
parser = ParserCreate("utf-8")
parser.Parse(text)

  Here's the content of the XML file:
  <?xml version="1.0" encoding="UTF-8"?>
<Book> 
  <Para>Un été torride</Para> 
</Book>

  Here's the error:
  UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 58: ordinal not in range(128)
   


To boldly go photographing where everyone has been before.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.