Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > expat parsing error

Reply
Thread Tools

expat parsing error

 
 
kaklis@gmail.com
Guest
Posts: n/a
 
      06-01-2010
Hi i'm doing the following:

def start_element(name, attrs):
print 'Start element:', name, attrs
def end_element(name):
print 'End element:', name
def char_data(data):
print 'Character data:', repr(data)

class SimpleServer(LineReceiver): # Using Twisted

def connectionMade(self):
print 'Connection from: ', self.transport.client

def connectionLost(self, reason):
print self.transport.client, 'Disconnected'

def dataReceived(self, line):
"""Here the XML Parser"""

p = xml.parsers.expat.ParserCreate()

p.StartElementHandler = start_element
p.EndElementHandler = end_element
p.CharacterDataHandler = char_data
p.Parse(line, 1)

I got the following error
--- <exception caught here> ---
File "/usr/lib/python2.6/site-packages/Twisted-10.0.0-py2.6-linux-
x86_64.egg/twisted/internet/selectreactor.py", line 146, in
_doReadOrWrite
why = getattr(selectable, method)()
File "/usr/lib/python2.6/site-packages/Twisted-10.0.0-py2.6-linux-
x86_64.egg/twisted/internet/tcp.py", line 460, in doRead
return self.protocol.dataReceived(data)
File "stdiodemo.py", line 419, in dataReceived
p.Parse(line, 1)
xml.parsers.expat.ExpatError: syntax error: line 1, column 0


The XML Message is coming in the form of:

POST /test/pcp/Listener HTTP/1.1
user-agent:hjahsjdhaskd asdja d
Host:127.0.0.1
Content-Length: 547

<pttv_control_message version="1.0-M4-SNAPSHOT" build="599"
xmlns="http://bytemobile.com/pttv">
<cmdReply>
<code>200</code>
<message>OK, found 5 session entries</message>
<sessionList>
<session>
<id>06d4d59bf8f1abf57cadfe10139dd874</id>
<subscriberId>82</subscriberId>
<deviceClass>android</deviceClass>
</session>
</sessionList>
</cmdReply>
</pttv_control_message>

Please give me some hints
 
Reply With Quote
 
 
 
 
John Bokma
Guest
Posts: n/a
 
      06-01-2010
"(E-Mail Removed)" <(E-Mail Removed)> writes:

> I got the following error
> --- <exception caught here> ---
> File "/usr/lib/python2.6/site-packages/Twisted-10.0.0-py2.6-linux-
> x86_64.egg/twisted/internet/selectreactor.py", line 146, in
> _doReadOrWrite
> why = getattr(selectable, method)()
> File "/usr/lib/python2.6/site-packages/Twisted-10.0.0-py2.6-linux-
> x86_64.egg/twisted/internet/tcp.py", line 460, in doRead
> return self.protocol.dataReceived(data)
> File "stdiodemo.py", line 419, in dataReceived
> p.Parse(line, 1)
> xml.parsers.expat.ExpatError: syntax error: line 1, column 0
>
>
> The XML Message is coming in the form of:
>
> POST /test/pcp/Listener HTTP/1.1


Does Expat get this line as well? If so, that's the reason why you get
an error at line 1, column 0.

--
John Bokma j3b

Hacking & Hiking in Mexico - http://johnbokma.com/
http://castleamber.com/ - Perl & Python Development
 
Reply With Quote
 
 
 
 
kaklis@gmail.com
Guest
Posts: n/a
 
      06-01-2010
On Jun 1, 9:51*am, John Bokma <(E-Mail Removed)> wrote:
> "(E-Mail Removed)" <(E-Mail Removed)> writes:
> > I got the following error
> > --- <exception caught here> ---
> > * File "/usr/lib/python2.6/site-packages/Twisted-10.0.0-py2.6-linux-
> > x86_64.egg/twisted/internet/selectreactor.py", line 146, in
> > _doReadOrWrite
> > * * why = getattr(selectable, method)()
> > * File "/usr/lib/python2.6/site-packages/Twisted-10.0.0-py2.6-linux-
> > x86_64.egg/twisted/internet/tcp.py", line 460, in doRead
> > * * return self.protocol.dataReceived(data)
> > * File "stdiodemo.py", line 419, in dataReceived
> > * * p.Parse(line, 1)
> > xml.parsers.expat.ExpatError: syntax error: line 1, column 0

>
> > The XML Message is coming in the form of:

>
> > POST /test/pcp/Listener HTTP/1.1

>
> Does Expat get this line as well? If so, that's the reason why you get
> an error at line 1, column 0.
>
> --
> John Bokma * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * j3b
>
> Hacking & Hiking in Mexico - *http://johnbokma.com/http://castleamber.com/- Perl & Python Development


Yes but how can i fix it, how to "ignore" the headers and parse only
the XML?
Thanks
 
Reply With Quote
 
John Bokma
Guest
Posts: n/a
 
      06-01-2010
"(E-Mail Removed)" <(E-Mail Removed)> writes:

> On Jun 1, 9:51*am, John Bokma <(E-Mail Removed)> wrote:
>> "(E-Mail Removed)" <(E-Mail Removed)> writes:
>> > I got the following error
>> > --- <exception caught here> ---
>> > * File "/usr/lib/python2.6/site-packages/Twisted-10.0.0-py2.6-linux-
>> > x86_64.egg/twisted/internet/selectreactor.py", line 146, in
>> > _doReadOrWrite
>> > * * why = getattr(selectable, method)()
>> > * File "/usr/lib/python2.6/site-packages/Twisted-10.0.0-py2.6-linux-
>> > x86_64.egg/twisted/internet/tcp.py", line 460, in doRead
>> > * * return self.protocol.dataReceived(data)
>> > * File "stdiodemo.py", line 419, in dataReceived
>> > * * p.Parse(line, 1)
>> > xml.parsers.expat.ExpatError: syntax error: line 1, column 0

>>
>> > The XML Message is coming in the form of:

>>
>> > POST /test/pcp/Listener HTTP/1.1

>>
>> Does Expat get this line as well? If so, that's the reason why you get
>> an error at line 1, column 0.

>
> Yes but how can i fix it, how to "ignore" the headers and parse only
> the XML?


The headers are followed by exactly one empty line, so you you simply
could remove lines up until including this empty line and then hand over
the data to the parser.

--
John Bokma j3b

Hacking & Hiking in Mexico - http://johnbokma.com/
http://castleamber.com/ - Perl & Python Development
 
Reply With Quote
 
Stefan Behnel
Guest
Posts: n/a
 
      06-01-2010
http://www.velocityreviews.com/forums/(E-Mail Removed), 01.06.2010 16:00:
> how can i fix it, how to "ignore" the headers and parse only
> the XML?


Consider reading the answers you got in the last thread that you opened
with exactly this question.

Stefan

 
Reply With Quote
 
kaklis@gmail.com
Guest
Posts: n/a
 
      06-01-2010
On Jun 1, 10:34*am, Stefan Behnel <(E-Mail Removed)> wrote:
> (E-Mail Removed), 01.06.2010 16:00:
>
> > how can i fix it, how to "ignore" the headers and parse only
> > the XML?

>
> Consider reading the answers you got in the last thread that you opened
> with exactly this question.
>
> Stefan


That's exactly, what i did but something seems to not working with the
solutions i had, when i changed my implementation from pure Python's
sockets to twisted library!
That's the reason i have created a new post!
Any ideas why this happened?
Thanks Stefan

 
Reply With Quote
 
John Bokma
Guest
Posts: n/a
 
      06-01-2010
"(E-Mail Removed)" <(E-Mail Removed)> writes:

> On Jun 1, 10:34*am, Stefan Behnel <(E-Mail Removed)> wrote:
>> (E-Mail Removed), 01.06.2010 16:00:
>>
>> > how can i fix it, how to "ignore" the headers and parse only
>> > the XML?

>>
>> Consider reading the answers you got in the last thread that you opened
>> with exactly this question.
>>
>> Stefan

>
> That's exactly, what i did but something seems to not working with the
> solutions i had, when i changed my implementation from pure Python's
> sockets to twisted library!
> That's the reason i have created a new post!
> Any ideas why this happened?


As I already explained: if you send your headers as well to any XML
parser it will choke on those, because the headers are /not/ valid /
well-formed XML. The solution is to remove the headers from your
data. As I explained before: headers are followed by one empty
line. Just remove lines up and until including the empty line, and pass
the data to any XML parser.

--
John Bokma j3b

Hacking & Hiking in Mexico - http://johnbokma.com/
http://castleamber.com/ - Perl & Python Development
 
Reply With Quote
 
kaklis@gmail.com
Guest
Posts: n/a
 
      06-01-2010
On Jun 1, 11:09*am, John Bokma <(E-Mail Removed)> wrote:
> "(E-Mail Removed)" <(E-Mail Removed)> writes:
> > On Jun 1, 10:34*am, Stefan Behnel <(E-Mail Removed)> wrote:
> >> (E-Mail Removed), 01.06.2010 16:00:

>
> >> > how can i fix it, how to "ignore" the headers and parse only
> >> > the XML?

>
> >> Consider reading the answers you got in the last thread that you opened
> >> with exactly this question.

>
> >> Stefan

>
> > That's exactly, what i did but something seems to not working with the
> > solutions i had, when i changed my implementation from pure Python's
> > sockets to twisted library!
> > That's the reason i have created a new post!
> > Any ideas why this happened?

>
> As I already explained: if you send your headers as well to any XML
> parser it will choke on those, because the headers are /not/ valid /
> well-formed XML. The solution is to remove the headers from your
> data. As I explained before: headers are followed by one empty
> line. Just remove lines up and until including the empty line, and pass
> the data to any XML parser.
>
> --
> John Bokma * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * j3b
>
> Hacking & Hiking in Mexico - *http://johnbokma.com/http://castleamber.com/- Perl & Python Development


Thank you so much i'll try it!
Antonis
 
Reply With Quote
 
kaklis@gmail.com
Guest
Posts: n/a
 
      06-01-2010
On Jun 1, 11:12*am, "(E-Mail Removed)" <(E-Mail Removed)> wrote:
> On Jun 1, 11:09*am, John Bokma <(E-Mail Removed)> wrote:
>
>
>
> > "(E-Mail Removed)" <(E-Mail Removed)> writes:
> > > On Jun 1, 10:34*am, Stefan Behnel <(E-Mail Removed)> wrote:
> > >> (E-Mail Removed), 01.06.2010 16:00:

>
> > >> > how can i fix it, how to "ignore" the headers and parse only
> > >> > the XML?

>
> > >> Consider reading the answers you got in the last thread that you opened
> > >> with exactly this question.

>
> > >> Stefan

>
> > > That's exactly, what i did but something seems to not working with the
> > > solutions i had, when i changed my implementation from pure Python's
> > > sockets to twisted library!
> > > That's the reason i have created a new post!
> > > Any ideas why this happened?

>
> > As I already explained: if you send your headers as well to any XML
> > parser it will choke on those, because the headers are /not/ valid /
> > well-formed XML. The solution is to remove the headers from your
> > data. As I explained before: headers are followed by one empty
> > line. Just remove lines up and until including the empty line, and pass
> > the data to any XML parser.

>
> > --
> > John Bokma * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * j3b

>
> > Hacking & Hiking in Mexico - *http://johnbokma.com/http://castleamber..com/-Perl & Python Development

>
> Thank you so much i'll try it!
> Antonis


Dear John can you provide me a simple working solution?
I don't seem to get it
 
Reply With Quote
 
John Machin
Guest
Posts: n/a
 
      06-02-2010
On Jun 2, 1:57*am, "(E-Mail Removed)" <(E-Mail Removed)> wrote:
> On Jun 1, 11:12*am, "(E-Mail Removed)" <(E-Mail Removed)> wrote:
>
>
>
> > On Jun 1, 11:09*am, John Bokma <(E-Mail Removed)> wrote:

>
> > > "(E-Mail Removed)" <(E-Mail Removed)> writes:
> > > > On Jun 1, 10:34*am, Stefan Behnel <(E-Mail Removed)> wrote:
> > > >> (E-Mail Removed), 01.06.2010 16:00:

>
> > > >> > how can i fix it, how to "ignore" the headers and parse only
> > > >> > the XML?

>
> > > >> Consider reading the answers you got in the last thread that you opened
> > > >> with exactly this question.

>
> > > >> Stefan

>
> > > > That's exactly, what i did but something seems to not working with the
> > > > solutions i had, when i changed my implementation from pure Python's
> > > > sockets to twisted library!
> > > > That's the reason i have created a new post!
> > > > Any ideas why this happened?

>
> > > As I already explained: if you send your headers as well to any XML
> > > parser it will choke on those, because the headers are /not/ valid /
> > > well-formed XML. The solution is to remove the headers from your
> > > data. As I explained before: headers are followed by one empty
> > > line. Just remove lines up and until including the empty line, and pass
> > > the data to any XML parser.

>
> > > --
> > > John Bokma * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * j3b

>
> > > Hacking & Hiking in Mexico - *http://johnbokma.com/http://castleamber.com/-Perl& Python Development

>
> > Thank you so much i'll try it!
> > Antonis

>
> Dear John can you provide me a simple working solution?
> I don't seem to get it


You're not wrong. Trysomething like this:

rubbish1, rubbish2, xml = your_guff.partition('\n\n')
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
expat parsing error kaklis@gmail.com Python 0 06-01-2010 12:59 PM
Want help on how we convert output to tabular format Using the expat parser (http://expat.sourceforge.net/) i have to parse the following xml file and print it on the screen in tabular format. sharan XML 1 10-26-2007 01:20 PM
Using the expat parser (http://expat.sourceforge.net/) i have to parse the following xml file and print it on the screen in tabular format. Want a c program on that! sharan XML 1 10-26-2007 07:56 AM
parsing XML with 'expat' Bjoern Hoehrmann XML 2 08-20-2007 09:09 PM
loosing data while parsing xml with expat Fabian Kr?ger XML 0 11-19-2003 12:24 PM



Advertisments