[zz]Python SOAP client with suds
2011-08-05 19:47
441 查看
http://www.jansipke.nl/python-soap-client-with-suds
he 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.
Then we download, unpack and install suds.
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.
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):
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:
We can get portions of this data by doing some XML handling. Let’s say we want to print the resultCode:
he 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.
print client.service.FindCountryAsString("194.145.200.104")
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:
print client.last_received()
<?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:
print client.last_received().getChild("soap:Envelope").getChild("soap:Header").getChild("ResponseHeader").getChild("resultCode").getText()
相关文章推荐
- php soapclient with wsse
- [zz]Python 3.4 and Pillow 2.4 with JPEG2000 (openjpeg 2) support in Ubuntu 14.04
- [zz]python with语句的注解
- java socket client to python server with utf-8
- Issue 71 - pymssql - Undefined symbols on Mac, CentOS, Redhat with pre-compiled build - A fast MS SQL Server client library for Python directly using C API instead of ODBC. It is Python DB-API 2.0 compliant. Works on Linux, *BSD, Solaris, Mac OS X and Win
- Call SOAP Web services with Ajax, Part 1: Build the Web services client
- python suds 出错"No handlers could be found for logger 'suds.client'"
- Call SOAP Web services with Ajax, Part 2: Extend the Web services client
- [zz]Make Yahoo! Web Service REST calls with Python
- python的suds的soap(webserivce)客户端编程
- How to pass SOAP headers into python SUDS that are not defined in WSDL file
- [zz]Scripting KVM with Python, Part 2: Add a GUI to manage KVM with libvirt and Python
- Python实现文件上传下载的SOAP Client
- [zz]Scripting KVM with Python, Part 1: libvirt
- 【ZZ】python with...as...用法
- Python安装cx_Oracle模块和suds.client模块调用webservice服务
- Studying python/SOAP/WSDL
- 在python2.6下搭建web service client
- 【Python】pip安装scrapy、mysqlclient出错的解决方法
- Rapid Web Applications with TurboGears: Using Python to Create Ajax-Powered Sites