Mysterious xml.sax Encoding Exception

JKPeck JKPeck at
Fri Feb 1 19:04:18 CET 2008

I have a module that uses xml.sax and feeds it a string of xml as in

The xml is always encoded in utf-16, and the XML string always starts
<?xml version="1.0" encoding="UTF-16" standalone="no"?>

This almost always works fine, but two users of this module get an
exception whatever input they use it on.  (The actual xml is generated
by an api in our application that returns an xml version of metadata
associated with the application's data.)

The exception is
xml.sax._exceptions.SAXParseException: <unknown>:1:30: encoding
specified in XML declaration is incorrect.

In both of these cases, there are only plain, 7-bit ascii characters
in the xml, and it really is valid utf-16 as far as I can tell.

Now here is the hard part: This never happens to me, and having gotten
the actual xml content from one of the users and fed it to the parser,
I don't get the exception.

What could be going on?  We are all on Python 2.5 (and all on an
English locale).

Any suggestions would be appreciated.
-Jon Peck

More information about the Python-list mailing list