本文目錄一覽:
怎麼安裝python 的擴展庫-suds?
首先建議你安裝一個擴展庫安裝工具,推薦easy_install工具,你可以在網上下載,也可以先去下載一個 ez_setup.py ,這個程序下載後用python.exe運行一下,會自動根據你的版本幫你下載和安裝一個easy_install,目前只支持到python2.6,看來python3目前還是沒有太多的公司在使用啊。。。
後面就可以用這個easy_install工具進行第三方庫的下載了,比如我要下載soaplib這個庫,可以執行easy_install soaplib,它會自己去相關網站查找這個庫,以及這個庫的依賴,如果你手工安裝,那依賴會把你搞瘋掉的
關於哪個庫更適用做webservice
現在網上查到最多的是ZSI或者叫soappy,實際上05年之後就沒有更新了,而且只支持到2.5,放棄
soaplib,這個目前2.0,還是不錯的,不過手冊不是太好讀,只有server端的用法,client我沒找到suds,這個我在用,用起來比較簡單,示例代碼如下:
[python] view plain copy
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 = “”
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
countryNetherlands/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=””
resultCode1000/resultCode
resultDescriptionSuccess/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()
python調用suds方法,拋出”對象實例沒有設置”的異常,為什麼
public MappingMongoConverter mongoConverter() throws UnknownHostException {
MappingMongoConverter converter = new MappingMongoConverter(mongoDbFactory(), mongoMappingContext());
converter.setTypeMapper(mongoTypeMapper());
return converter;
}
python用suds 調用webservice方法的時候報錯。
其實用Python進行webservice通信進行數據交換,就是拼接字元串,沒必要用第三方的庫。
原創文章,作者:小藍,如若轉載,請註明出處:https://www.506064.com/zh-tw/n/193763.html