在python中使用suds更新sharepoint列表项

时间:2014-12-27 08:30:01

标签: python web-services sharepoint suds

我使用此代码在python中使用suds更新sharepoint列表项:

from suds.sax.element import Element

batch = Element('Batch')
batch.set('OnError','Return')
batch.set('ListVersion','1')

method = Element('Method')
method.set('ID','1')
method.set('Cmd','Update')

field1 = Element('Field').setText(1)
field1.set('Name','ID')

field2 = Element('Field').setText("some text")
field2.set('Name','Title')

method.append(field1)
method.append(field2)
batch.append(method)

updates = Element('ns1:updates')
updates.append(batch)

client.service.UpdateListItems('mmnn', updates)

但我收到了这个错误:

suds.WebFault: Server raised fault: 'Exception of type 'Microsoft.SharePoint.SoapServer.SoapServerException' was thrown.'

请注意,我之前使用过这段代码并且有效,但我不知道为什么它现在不起作用。请帮助我。

1 个答案:

答案 0 :(得分:1)

我使用此方法将纯XML发送到SharePoint Web服务,使用SharePoint Web服务文档,我可以完成我需要的所有操作:

xml = r"""
<soap:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
  <soap:Body>
    <UpdateListItems xmlns="http://schemas.microsoft.com/sharepoint/soap/">
      <listName>PyTest</listName>
      <updates>
        <Batch OnError="Continue" ListVersion="0">
           <Method ID="1" Cmd="New">
              <Field Name="ID">New</Field>
              <Field Name="Title">{0}</Field>
              <Field Name="Sex">{1}</Field>
              <Field Name="FirstName">{2}</Field>
              <Field Name="LastName">{3}</Field>
              <Field Name="CustomerNum">{4}</Field>
           </Method>
        </Batch>
      </updates>
    </UpdateListItems>
  </soap:Body>
</soap:Envelope>
    """.format(st, sex, fname, lname, costname)

res = client.service.UpdateListItems(__inject={'msg': xml})