Web Services examples using "raw" xml?
stefan_ml at behnel.de
Tue Aug 25 06:54:28 CEST 2009
John Gordon wrote:
> I'm developing a program that will use web services, which I have never
> used before.
> There are several tutorials out there that advise you to get the WSDL
> and then call a method (such as wsdl2py) that inspects the wsdl and
> automagically generates the python classes and methods you need for
> interacting with that web service.
There are a number of tools that help in building WS clients. One is
soaplib. It's pretty easy to use and was recently ported (V0.8) to the lxml
XML library. I actually still use a 0.7.x, also fixed to work with Py2.3.
It doesn't do any code generation. Instead, you have to write up a short
code snippet that describes the WS interface. Works pretty well.
> I tried WSDL.Proxy() from the SOAPpy package and eventually end up
> with this error:
> xml.parsers.expat.ExpatError: not well-formed (invalid token): line 1, column 6
Is that while parsing the WSDL file? Have you tried pushing it through an
XML parser yourself (or opening it with an XML editor) to see if it really
Or does this happen while communicating with the remote side? (in which
case I'd trap the wire and look at the transferred XML messages)
> I tried Client() from the suds package, and got this error:
> File "/usr/lib/python2.3/site-packages/suds/client.py", line 59
> SyntaxError: invalid syntax
That's a Py2.4-ism. You can make the code backwards compatible by replacing all
some_function = classmethod(some_function)
That's how I fixed up soaplib, BTW.
> So I decided to take a step back and see if I could bypass all the fancy
> automagic methods and just create my own SOAP xml message from scratch
> and then send it to the web server. That would work, surely.
Yes, that's a good way also. And it avoids an additional dependency on a
convoluted SOAP library.
> But I'm having a tough time finding some good examples of that, because
> all the tutorials I've found just tell you to use the aforementioned
> magic methods, which unfortunately don;t seem to be working for me.
More information about the Python-list