2014-01-23 31 views
0

我正在使用Python Suds来使用Sharepoint 2007提供的Web服务。 特别我想使用由Lists.aspx服务提供的UpdateListItems。如何在Python Suds中修改SOAP信封?

正如在msdn的docs中提到的,我创建了xml参数。但它给我一个SoapServerException。回溯没有任何用处,因为Sharepoint 2007在没有提供任何细节的情况下盲目抛出异常。

我还遵循指南here在为UpdateListItems示例给出的Suds文档。但没有用。我认为问题是,泡沫正在为我的XML是这样的:

<?xml version="1.0" encoding="UTF-8"?> 
<SOAP-ENV:Envelope xmlns:ns0="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="http://schemas.microsoft.com/sharepoint/soap/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"> 
    <SOAP-ENV:Header/> 
    <ns0:Body> 
     <ns1:UpdateListItems> 
     <ns1:listName>MyDocuments</ns1:listName> 
     <ns0:updates> 
      <Batch OnError="Continue" ListVersion="1"> 
       <Method ID="1" Cmd="Delete"> 
        <Field Name="ID">7</Field> 
        <Field Name="FieldRef">http://win2003/sharepoint_site/MyDocuments/aal.txt</Field> 
       </Method> 
      </Batch> 
     </ns0:updates> 
     </ns1:UpdateListItems> 
    </ns0:Body> 
</SOAP-ENV:Envelope> 

但在泡沫文档的例子是这样的:

<SOAP-ENV:Envelope xmlns:ns0="http://schemas.microsoft.com/sharepoint/soap/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/"> 
    <SOAP-ENV:Header/> 
    <SOAP-ENV:Body> 
     <ns0:UpdateListItems> 
     <ns0:listName>MySchedule</ns0:listName> 
     <Batch OnError="Continue" ListVersion="1"> 
      <Method ID="1" Cmd="New"> 
       <Field Name="ID">New</Field> 
       <Field Name="Title">Toasting</Field> 
       <Field Name="EndDate">2009-03-07 18:00:00</Field> 
       <Field Name="EventDate">2009-03-07 17:00:00</Field> 
       <Field Name="Location">Everywhere</Field> 
       <Field Name="Description">Stuff!</Field> 
      </Method> 
     </Batch> 
     </ns0:UpdateListItems> 
    </SOAP-ENV:Body> 
</SOAP-ENV:Envelope> 

我认为这个问题是体内的元素。这个例子说ns0,而我拿到ns1`。

于是,我就用插件,如杜尚这个问题在这里提出:

python suds wrong namespace prefix in SOAP request

所以我用marshalled()方法和我的代码如下所示:

class UpdatePlugin(MessagePlugin): 
    def marshalled(self, context): 
     body = context.envelope.getChild("Body") 
     updateListItems = body[0] 
     listName = body[1] 
     updateListItems.setPrefix("ns0") 
     listName.setPrefix("ns0") 

然而上面的最后一行给出了以下错误:

ERROR:suds.plugin:'NoneType' object has no attribute 'setPrefix' 

所以bodyNone本身。显然我做错了什么。请帮帮我。

回答

1

<ns0:updates><ns1:updates>,并尝试client.options.prettyxml = True(从this answer),因为肥皂水是极其车和unmaintained