2017-04-02 57 views
4

我在發送泡沫請求時遇到問題。如何使用請求中的多個元素使用泡沫客戶端發送請求

我發送的請求,以不同的方法只使用下列內容:

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' 

回答

0

我假設您使用的是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) 
相關問題