SOAP WSDL SUDS PYTHON
2022-06-03 本文已影响0人
wyude
安装suds
pip install suds
from suds.client import Client
from suds.transport.https import HttpAuthenticated
t = HttpAuthenticated(username=’admin’,password=’123′)
test = Client(‘http://xxx.xxx.xx.xxx/WebService/ws/Service?wsdl',transport=t)
print(test)
print(test.service.fun()) #fun为WebService提供的接口
2. 构造WebService接口需要的参数
1)简单调用,无参数的情况
client=Client(url)
client.service.fun()
2)传递对象参数(方法1)当type为复合参数时,理解为对象
通过查看远程方法,发现fun 接口的参数类型为 paramType,有p1,p2两个属性
client=Client(url)
m=client.factory.create('paramType')#当type为复合参数时,理解为对象
m.p1="param 1"
m.p2="param 2"
result=client.service.fun(m)
print(result)
3)传递对象参数(方法2)当type为简单类型时 例如xs:string
client=Client(url)
print(client.service.fun(p1="parram 1", p2="param 2"))
4)suds把异常包装成元组输出
client=Client(url)
client=Client(url, faults=False)
result=client.service.funIn("error param")
print(result)