Learn how easy it is to sync an existing GitHub or Google Code repo to a SourceForge project! See Demo


#3 XML parsing the output raises UnicodeEncodeError

Client Lib v1.0

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'])
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.


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

  • 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.

    • assigned_to: nobody --> ctctlabs
    • status: open --> open-fixed
    • status: open-fixed --> closed-fixed