The library suds allows Python to make SOAP calls (that is, Python is the web service client).
We start by installing the suds library on an Ubuntu machine. The Python setuptools are needed to install suds.
sudo apt-get install python-setuptools
Then we download, unpack and install suds.
wget https://fedorahosted.org/releases/s/u/suds/python-suds-0.3.7.tar.gz tar -zxvf python-suds-0.3.7.tar.gz cd python-suds-0.3.7 sudo python setup.py install
The library is now ready to use. We start by importing the suds library, creating a client based on a SOAP url, and asking the library to print the SOAP web service methods that are available to us.
import suds url = "http://www.ecubicle.net/iptocountry.asmx?wsdl" client = suds.client.Client(url) print client
From the output of the last print command, we learn that there is a method called FindCountryAsString that takes one argument: the IP address.
And it shows (edited for readability):
<?xml version="1.0"?> <IPAddressService> <country>Netherlands</country> </IPAddressService>
Normally you want to have the contents of the SOAP body. This is what suds provides in a very elegant way. However, you’re a bit stuck when you want to get something from the SOAP header. The author of suds realised this and made a backdoor to get the information anyway. We start by showing what the function last_received contains:
<?xml version="1.0" encoding="UTF-8"?> <soap:Envelope> <soap:Header> <ResponseHeader xmlns=""> <resultCode>1000</resultCode> <resultDescription>Success</resultDescription> </ResponseHeader> </soap:Header> <soap:Body> ... </soap:Body> </soap:Envelope>
We can get portions of this data by doing some XML handling. Let’s say we want to print the resultCode:
Hello!, I have a question: where do you use SUDS as an example? In a python interpreter? Thanks a lot!
Yes, the code parts that start with “import suds” must be used within the Python interpreter. You can type “python” on the command prompt and then type the text as shown on the site, or save the text to a file named suds-test.py and run it as “python suds-test.py” from the command prompt.
Thanks a lot! I did it. Now i try to invoke from my instance in Plone. Bye
I tried the example above and it works within python-suds-0.3.7 directory.
However, the same file doesnt work from another directory.
Do I need to change some path variables so that suds can be imported from anywhere?
Any help in this regard would be highly appreciated.
ignore my previous comment. reinstalled and it worked
Hello again!, I tried to invoke a python function from my instance in plone, but i couldnt because the imports of suds return a error. Do you know how i must define it? This is my function:
import suds (these line cause the error)
url = “http://vivaldi.cpe.ku.ac.th:443/ACSWWebserviceV1/wsdl/ACSWWebService.wsdl”
client = suds.client.Client(url)
Thank you so much!
I don’t have experience with Plone. Perhaps you can search for others that tried to add python modules to the Plone installation.
You likely have not yet installed ‘suds’; you can get around that easily by running `pip install suds` or `easy_install suds`.
This worked great.
Keep up the good work. Now I can integrate suds in my own application.
I am using Python 2.7.1 on Windows machine. I have installed suds module (04) but while importing I am getting below exception:
ImportError: No module named suds
I had the same issue, it was on Redhat though, it turned out that the installer was placing the suds modules in the 2.4 dist and not the 2.6 which is what I’m using. Make sure suds is installed in the right directory
Hey thanks a lot!! it worked for me
Thanks for sharing the examples – this is just what I needed.
I am developing a SOAP server and I needed a way to automate the testing procedures – SUDS is very simple to use, so I’m sticking to it.