1. 程式人生 > >Python使用suds呼叫webserver介面

Python使用suds呼叫webserver介面

首先,要安裝suds包,suds包中可以呼叫client方法進行連線

對於初步學習python的使用者來說,pycharm安裝suds教程 :  File--->settings...--->Project:xx--->Project Interpreter--->點選右方的加號--->在搜尋框中搜索suds--->點選想要安裝的版本(如:suds-py3)--->Install Package(完成安裝)

如果出現報錯:

安裝成功後,開始進行連線命令如下:

from suds.client import Client  
url = 'webservice介面'  
client = Client(url)  
  
#檢視該service提供的方法  
print(client)
#列印結果如下:
  
Suds - version: 0.3.3 build: (beta) R397-20081121  
  
Service (WebServiceTestBeanService) tns="http://test.server.enterprise.rhq.org/"  
   Prefixes (1):  
     ns0 = "http://test.server.enterprise.rhq.org/"  
   Ports (1):  
     (Soap)  
       Methods:  
         addPerson(Person person, )  
         echo(xs:string arg0, )  
         getList(xs:string str, xs:int length, )  
         getPercentBodyFat(xs:string name, xs:int height, xs:int weight)  
         getPersonByName(Name name, )  
         hello()  
         testExceptions()  
         testListArg(xs:string[] list, )  
         testVoid()  
         updatePerson(AnotherPerson person, name name, )  
   Types (23):  
     Person  
     Name  
     Phone  
     AnotherPerson
#Methods中都是介面中的方法,括號中的內容,則是要傳的引數,接下來做掉方法操作,如:
resu = client.service.getPercentBodyFat(name='Tom', height=88, weight=180)  
print(resu)#返回資料