2010-05-20 29 views
0

這裏是我的代碼:SUDS渲染重複的節點和包裝它的一切

#Make the SOAP connection 
url = "https://api.channeladvisor.com/ChannelAdvisorAPI/v1/InventoryService.asmx?WSDL" 
headers = {'Content-Type': 'text/xml; charset=utf-8'} 
ca_client_inventory = Client(url, location="https://api.channeladvisor.com/ChannelAdvisorAPI/v1/InventoryService.asmx", headers=headers) 
#Make the SOAP headers 
login = ca_client_inventory.factory.create('APICredentials') 
login.DeveloperKey = 'REMOVED' 
login.Password = 'REMOVED' 
#Attach the headers 
ca_client_inventory.set_options(soapheaders=login) 

synch_inventory_item_list = ca_client_inventory.factory.create('SynchInventoryItemList') 
synch_inventory_item_list.accountID = "REMOVED" 

array_of_inventory_item_submit = ca_client_inventory.factory.create('ArrayOfInventoryItemSubmit') 
for product in products: 
    inventory_item_submit = ca_client_inventory.factory.create('InventoryItemSubmit') 
    inventory_item_list = get_item_list(product) 
    inventory_item_submit = [inventory_item_list] 
    array_of_inventory_item_submit.InventoryItemSubmit.append(inventory_item_submit) 

synch_inventory_item_list.itemList = array_of_inventory_item_submit 

#Call that service baby! 
ca_client_inventory.service.SynchInventoryItemList(synch_inventory_item_list) 

下面是它的輸出:

<?xml version="1.0" encoding="UTF-8"?> 
<SOAP-ENV:Envelope xmlns:ns0="http://api.channeladvisor.com/webservices/" xmlns:ns1="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:tns="http://api.channeladvisor.com/webservices/" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"> 
    <SOAP-ENV:Header> 
     <tns:APICredentials> 
     <tns:DeveloperKey>REMOVED</tns:DeveloperKey> 
     <tns:Password>REMOVED</tns:Password> 
     </tns:APICredentials> 
    </SOAP-ENV:Header> 
    <ns1:Body> 
     <ns0:SynchInventoryItemList> 
     <ns0:accountID> 
      <ns0:accountID>REMOVED</ns0:accountID> 
      <ns0:itemList> 
       <ns0:InventoryItemSubmit> 
        <ns0:Sku>1872</ns0:Sku> 
        <ns0:Title>The Big Book Of Crazy Quilt Stitches</ns0:Title> 
        <ns0:Subtitle></ns0:Subtitle> 
        <ns0:Description>Embellish the seams and patches of crazy quilt projects with over 75 embroidery stitches and floral motifs. You&apos;ll use this handy reference book again and again to dress up wall hangings, pillows, sachets, clothing, and other nostalgic creations.</ns0:Description> 
        <ns0:Weight>4</ns0:Weight> 
        <ns0:FlagStyle/> 
        <ns0:IsBlocked xsi:nil="true"/> 
        <ns0:ISBN></ns0:ISBN> 
        <ns0:UPC>028906018721</ns0:UPC> 
        <ns0:EAN></ns0:EAN> 
        <ns0:QuantityInfo> 
        <ns0:UpdateType>UnShipped</ns0:UpdateType> 
        <ns0:Total>0</ns0:Total> 
        </ns0:QuantityInfo> 
        <ns0:PriceInfo> 
        <ns0:Cost>0.575</ns0:Cost> 
        <ns0:RetailPrice xsi:nil="true"/> 
        <ns0:StartingPrice xsi:nil="true"/> 
        <ns0:ReservePrice xsi:nil="true"/> 
        <ns0:TakeItPrice>6.95</ns0:TakeItPrice> 
        <ns0:SecondChanceOfferPrice xsi:nil="true"/> 
        <ns0:StorePrice>6.95</ns0:StorePrice> 
        </ns0:PriceInfo> 
        <ns0:ClassificationInfo> 
        <ns0:Name>Books</ns0:Name> 
        <ns0:AttributeList> 
         <ns0:ClassificationAttributeInfo> 
          <ns0:Name>Designer/Author</ns0:Name> 
          <ns0:Value>Patricia Eaton</ns0:Value> 
         </ns0:ClassificationAttributeInfo> 
         <ns0:ClassificationAttributeInfo> 
          <ns0:Name>Trim Size</ns0:Name> 
          <ns0:Value></ns0:Value> 
         </ns0:ClassificationAttributeInfo> 
         <ns0:ClassificationAttributeInfo> 
          <ns0:Name>Binding</ns0:Name> 
          <ns0:Value>Leaflet</ns0:Value> 
         </ns0:ClassificationAttributeInfo> 
         <ns0:ClassificationAttributeInfo> 
          <ns0:Name>Release Date</ns0:Name> 
          <ns0:Value>11/1/1999 0:00:00</ns0:Value> 
         </ns0:ClassificationAttributeInfo> 
         <ns0:ClassificationAttributeInfo> 
          <ns0:Name>Skill Level</ns0:Name> 
          <ns0:Value></ns0:Value> 
         </ns0:ClassificationAttributeInfo> 
         <ns0:ClassificationAttributeInfo> 
          <ns0:Name>Pages</ns0:Name> 
          <ns0:Value>20</ns0:Value> 
         </ns0:ClassificationAttributeInfo> 
         <ns0:ClassificationAttributeInfo> 
          <ns0:Name>Projects</ns0:Name> 
          <ns0:Value></ns0:Value> 
         </ns0:ClassificationAttributeInfo> 
        </ns0:AttributeList> 
        </ns0:ClassificationInfo> 
        <ns0:ImageList> 
        <ns0:ImageInfoSubmit> 
         <ns0:PlacementName>ITEMIMAGEURL1</ns0:PlacementName> 
         <ns0:FilenameOrUrl>1872.jpg</ns0:FilenameOrUrl> 
        </ns0:ImageInfoSubmit> 
        </ns0:ImageList> 
       </ns0:InventoryItemSubmit> 
      </ns0:itemList> 
     </ns0:accountID> 
     </ns0:SynchInventoryItemList> 
    </ns1:Body> 
</SOAP-ENV:Envelope> 

看看它是如何創建的帳戶ID節點兩次,包裝整個東西在裏面?爲什麼?我如何讓它停止?!

編輯:我只注意到這個在SUDS輸出:

(Content){ 
    tag = "accountID" 
    value = 
     (SynchInventoryItemList){ 
     accountID = "REMOVED" 
     itemList = 
      (ArrayOfInventoryItemSubmit){ 
       InventoryItemSubmit[] = 

        (InventoryItemSubmit){ 

這是什麼標籤? ...去檢查文檔

+0

我能看到的標籤被皁液代碼設定我,但我不明白的方式來訪問它。 :( – KacieHouser 2010-05-20 18:32:40

回答

0

答案在我的代碼的最後一行我需要這樣做:

ca_client_inventory.service.SynchInventoryItemList(accountID, array_of_inventory_item_submit) 

哪裏帳戶ID是一個包含字符串帳戶ID

我被jortel在告訴變量#suds IRC聊天室:「suds提供了一個rpc接口,可將用戶從soap消息類型中分離出來」並且調用中的新參數也來自他。希望這可以幫助某人。

0

這可能是WSDL或SUDS中的錯誤的問題。您是否比較了WSDL與SUDS提供的SOAP信封的內容?

+0

- - KacieHouser 2010-05-20 16:35:25

+0

那不是很漂亮,但它不是WSDL – KacieHouser 2010-05-20 16:35:43

+0

我在WSDL提供商組中看到有人遇到同樣的問題,但他們沒有報告他們如何修復它。 – KacieHouser 2010-05-20 16:37:47

0

有同樣的問題,並從菲利普·海恩斯這個link這個答案這樣做是爲了通過菲利普·海恩斯因爲文檔實例的method.soap.input.body.wrapped屬性設置爲True問題是造成解釋me.As。這是因爲wsdl.py中的Definitions.set_wrapped方法在將值設置爲True時似乎不應該。

通過設置客戶端unwrap選項嘗試使用此方法False

my_client = Client(url, unwrap=False)