如何使用请求中的多个元素使用泡沫客户端发送请求
问题描述:
我在发送泡沫请求时遇到问题。如何使用请求中的多个元素使用泡沫客户端发送请求
我发送的请求,以不同的方法只使用下列内容:
from suds.client import Client
client = Client(wsdlurl)
client.service.Login(name, employid)
这回来了姓名和employid正确的反应是登录的直接子元素。
但我怎么可以使用下面的发送一个请求:
<soapenv:Body>
<v12:getStuff>
<v12:stuffSelect>
<!--Optional:-->
<v12:stuffIDs>
<!--Zero or more repetitions:-->
<v12:num></v12:num>
</v12:stuffIDs>
</v12:stuffSelect>
</v12:getStuff>
</soapenv:Body>
</soapenv:Envelope>
这样做的原因是这样我就可以添加动态价值为NUM
我已经尝试过这样的:
return self.client.service.getStuff.stuffSelect.stuffIDs(**{'stuffID': stuff_id, })
但得到这个错误
AttributeError: 'Method' object has no attribute 'stuffSelector'
答
我假设您使用的是https://bitbucket.org/jurko/suds。你必须知道你的wsdl接口;泡沫可以在运行时部分提供:
# ... 'client' via wsdl url, login
# get example
http_status, payload = client.service.your_wsdl_get_stuff_method()
stuffIDs = []
if http_status == 200:
for stuff_id in payload: # depending on your wsdl
stuffIDs.append(stuff_id)
# upload example
stuffSelect = client.factory.create('stuffSelect') # structure generated by suds from wsdl
stuffSelect.your_wdsl_stuff_ids_name = stuffIDs # (maybe debug to see your name)
params = foo, bar, stuffSelect
svr_response = client.service.your_wsdl_upload_method(*params)