wddx problem with entities

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tim Arnold

    #1

    wddx problem with entities

    I'm confused about why I get this error:
    UnicodeError: ASCII encoding error: ordinal not in range(128)

    when I try to load a wddx file containing this string:
    <string>The image file, gif/aper&#231;u.png , does
    not exist.</string>

    When I loop through the file as if it's text and check the ord() value of
    each character, of course it's clean. Do I have to replace numbered entities
    in the wddx file before I can wddx.load() it?
    thanks!
    --tim

    example program:
    -------------------
    from xml.marshal import wddx

    datastring = '''<?xml version="1.0"?>
    <!DOCTYPE wddxPacket SYSTEM "wddx_0090.dtd" >
    <wddxPacket version="0.9">
    <header/>
    <data><struct >
    <string>The image file, gif/aper&#231;u.png ,does not exist.</string>
    </struct></data></wddxPacket>'''

    data = wddx.loads(data string)


  • Tim Arnold

    #2
    Re: wddx problem with entities

    "Tim Arnold" <tiarno@sas.com > wrote in message
    news:e66k6n$bc5 $1@foggy.unx.sa s.com...[color=blue]
    > I'm confused about why I get this error:
    > UnicodeError: ASCII encoding error: ordinal not in range(128)
    >
    > when I try to load a wddx file containing this string:
    > <string>The image file, gif/aper&#231;u.png , does
    > not exist.</string>
    >
    > When I loop through the file as if it's text and check the ord() value of
    > each character, of course it's clean. Do I have to replace numbered
    > entities in the wddx file before I can wddx.load() it?
    > thanks!
    > --tim
    >
    > example program:
    > -------------------
    > from xml.marshal import wddx
    >
    > datastring = '''<?xml version="1.0"?>
    > <!DOCTYPE wddxPacket SYSTEM "wddx_0090.dtd" >
    > <wddxPacket version="0.9">
    > <header/>
    > <data><struct >
    > <string>The image file, gif/aper&#231;u.png ,does not exist.</string>
    > </struct></data></wddxPacket>'''
    >
    > data = wddx.loads(data string)[/color]

    Replying to my own post.
    I got around this problem, which *looks* like a bug to me, (although I'm
    sure I don't understand the internals of xml.marshal) with this:

    self.data = wddx.loads(''.j oin(codecs.open (self.filename,
    errors='ignore' ,encoding='asci i').readlines() ))
    where self.filename contains the numbered entity.

    just in case anyone else out there is using wddx to communicate between
    python and php.

    --Tim Arnold



    Comment

    Working...