#3 XML parsing the output raises UnicodeEncodeError

Client Lib v1.0
closed-fixed
5
2010-02-10
2010-02-05
Anonymous
No

line 170 of __init__.py revision 11 raises a UnicodeEncodeError exception for some of my constant contact data.

I changed it from:
xml = ET.fromstring(response['body'])
to:
xml = ET.fromstring(response['body'].encode('ascii','xmlcharrefreplace'))

and that subdues the exception. It depends on how the library is being used whether this is a sufficient fix, I'd guess. Attached is my change.

Discussion

  • Nobody/Anonymous

    patch to init.py. sorry for the lib subdir assumption.

     
  • Constant Contact Labs

    Thanks for the post. The changes have been made to the library.

    CTCT data returned is UTF-8 and the fromstring method in the ElementTree library uses ASCII and does not allow you to specify a parser. Encoding the response before using invoking fromstring should eliminate any problems users will have with unencodable characters. xmlcharrefreplace will replace unencodable characters with numeric character references which will be sufficient for most people. If anyone knows of a way to parse the XML into an ET object using UTF-8 let me know as this would be ideal.

     
  • Constant Contact Labs

    • assigned_to: nobody --> ctctlabs
    • status: open --> open-fixed
     
  • Constant Contact Labs

    • status: open-fixed --> closed-fixed
     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks