[Fedora-suds-list] Invalid token with string, OK as file

Jeff Ortel jortel at redhat.com
Wed Mar 3 01:26:48 UTC 2010



On 03/02/2010 04:45 PM, Joshua J. Kugler wrote:
> I'm trying out suds (0.4 trunk) and getting a weird behavior with the
> result.  If I pass the result of a call into a sax parser, I get a 'not
> well formed (invalid token)' error.  If I save that same result to a
> file, then pass that file to the parser, it works.  If I read that
> string from the file, and pass it to the parser, it works.
>
> Any ideas?
>
> Here's a short script showing the problem.
>
> #!/usr/bin/python
>
> import os
> import suds
>
> url = 'http://www.weather.gov/forecasts/xml/DWMLgen/wsdl/ndfdXML.wsdl'
> client = suds.client.Client(url)
>
> # print client
>
> result = client.service.NDFDgenByDay(39.0000, -77.0000,
>                                       2004-04-27, 1, '12 hourly')

"result" is actually a class of type suds.sax.text.Text which is a subclass of unicode. 
Seems that either the StringIO or expat parser has a problem unicode.  Probably the 
StringIO.  The reason it works to write to a file and then read it again is that when you 
read(), you now have a str object.  When reading directly from a file, the parser is 
reading a file-like object.

>
> print 'Result:\n', result
>
> try:
>      p = suds.sax.parser.Parser()
>      print 'From string:', p.parse(string=result)

So, this:

 > print 'From string:', p.parse(string=str(result))

works and this:

 > print 'From string:', p.parse(string=unicode(result))

does not.

I'll look into this further.

> except Exception, e:
>      print 'Oops:', e
>
> open('nws_out.xml', 'w').write(result)
>
> print 'From file:', repr(p.parse(file=open('nws_out.xml')))
> print 'From file:', repr(p.parse(string=open('nws_out.xml').read()))
>

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 5126 bytes
Desc: S/MIME Cryptographic Signature
Url : http://lists.fedoraproject.org/pipermail/suds/attachments/20100302/50db3216/attachment.bin 


More information about the suds mailing list