如何使用带有请求中的多个元素的suds客户端发送请求

时间:2017-04-02 14:34:29

标签: python sax suds

我在发送suds请求时遇到问题。

我使用以下内容向其他方法发送了请求:

from suds.client import Client

   client = Client(wsdlurl)

   client.service.Login(name, employid)

由于name和employid是Login的直接子元素,因此返回正确的响应。

但是如何使用以下内容发送请求:

 <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'

1 个答案:

答案 0 :(得分:0)

我假设你正在使用https://bitbucket.org/jurko/suds。你必须知道你的wsdl接口; suds可以在运行时部分提供:

# ... '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)