"Decoding unicode is not supported" in unusual situation

John Nagle nagle at animats.com
Wed Mar 7 03:25:52 EST 2012


I'm getting

line 79, in tounicode
return(unicode(s, errors='replace'))
TypeError: decoding Unicode is not supported

from this, under Python 2.7:

def tounicode(s) :
     if type(s) == unicode :
         return(s)
     return(unicode(s, errors='replace'))

That would seem to be impossible.  But it's not.
"s" is generated from the "suds" SOAP client.  The documentation
for "suds" says:

"Suds leverages python meta programming to provide an intuative API for 
consuming web services. Runtime objectification of types defined in the 
WSDL is provided without class generation."

I think that somewhere in "suds", they subclass the "unicode" type.
That's almost too cute.

The proper test is

	isinstance(s,unicode)


					John Nagle





More information about the Python-list mailing list