logo       

Re: XML Unicode Error: msg#00252

org.google.api.calendar

Subject: Re: XML Unicode Error


I'm not an expert in Python unicode handling, but the following page
is worth a look:

http://www.onlamp.com/pub/a/python/excerpt/pythonckbk_chap1/index.html

Fromits description, it sounds like the error below occurs when
Python tries to convert a bytestring (which it assumes is ASCII) to a
Unicode string and discovers characters that don't appear to be valid
ascii characters.

The following "rule" looks particularly relevant:

"Whenever your program receives text data "from the outside" (from the
network, from a file, from user input, etc.), construct unicode
objects immediately. Find out the appropriate encoding, for example,
from an HTTP header, or look for an appropriate convention to
determine the encoding to use."

In the case of the GData Atom feed, the "appropriate encoding" (as
expressed by both the HTTP header and the XML encoding attribute is
"utf-8".

Hope this helps!

-- Kyle

On 9/26/06, gregpinero@xxxxxxxxx <gregpinero@xxxxxxxxx> wrote:
>
> Hi there, I pull back a query and I'm simply trying to encode the XML
> data returned in UTF-8 which it already should be in and Python throws
> an error. Could this be a bug in google's data?
>
> Details (Hope posting doesn't lose encoding)
> Code:
> data = data.encode("utf-8")
>
> Error: (position 370 ends up being the enye in my name or close to it)
> UnicodeDecodeError: 'ascii' codec can't decode byte 0xc3 in position
> 370: ordinal not in range(128)
>
> Partial XML (data)
> <?xml version='1.0' encoding='UTF-8'?><feed
> xmlns='http://www.w3.org/2005/Atom'
> xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/'
> xmlns:gd='http://schemas.google.com/g/2005'
> xmlns:gCal='http://schemas.google.com/gCal/2005'><id>http://www.google.com/calendar/feeds/default/private/full</id><updated>2006-09-27T04:28:21.000Z</updated><title
> type='text'>Gregory Piñero</title><subtitle type='text'>Includes old
> Outlook stuff</subtitle><link
>
> ...
>
>
> >
>



<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise