elementtree.ElemenTree barfs on my Safari Cookies file

skip at pobox.com skip at pobox.com
Sat Nov 12 19:31:40 EST 2005


Safari stores its cookies in XML format.  Looking to try and add support for
it to cookielib I started by first trying to parse it with Fredrik Lundh's
elementtree package.  It complained about an invalid token.  Looking at the
spot it indicated in the file, I found a non-ASCII, but (as far as I can
tell) perfectly valid utf-8 string.

I whittled the plist file down to what I've attached.  With it I get

    >>> e = elementtree.ElementTree.parse("Cookies.plist")
    Traceback (most recent call last):
      File "<stdin>", line 1, in ?
      File "/Users/skip/local/lib/python2.5/site-packages/elementtree/ElementTree.py", line 864, in parse
        tree.parse(source, parser)
      File "/Users/skip/local/lib/python2.5/site-packages/elementtree/ElementTree.py", line 588, in parse
        parser.feed(data)
      File "/Users/skip/local/lib/python2.5/site-packages/elementtree/ElementTree.py", line 1132, in feed
        self._parser.Parse(data, 0)
    xml.parsers.expat.ExpatError: not well-formed (invalid token): line 17, column 12

I had no trouble decoding that string as unicode.  Any ideas what's wrong?

Thx,

Skip

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/octet-stream
Size: 511 bytes
Desc: not available
URL: <http://mail.python.org/pipermail/python-list/attachments/20051112/d97b5b07/attachment.obj>


More information about the Python-list mailing list