I am using Python Suds to use the Web Service provided by Sharepoint 2007. Specifically I want to use the UpdateListItems provided by the Lists.aspx service.
As mentioned in the docs at msdn, I am creating the xml parameter. But it throws me a SoapServerException
. The traceback isnt any use because Sharepoint 2007 blindly throws the exception without giving any details.
I also followed the guidelines here at the Suds docs given for the UpdateListItems example. But to no use. I think the problem is that the XML that Suds is making for me is this:
<?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>
But the example at suds docs looks like this:
<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>
I think the problem is the element inside Body. The example says ns0
while I get ns1`.
So I tried to use Plugins, as suggested by dusan in this question here:
python suds wrong namespace prefix in SOAP request
So I am using marshalled()
method and my code looks like this:
class UpdatePlugin(MessagePlugin):
def marshalled(self, context):
body = context.envelope.getChild("Body")
updateListItems = body[0]
listName = body[1]
updateListItems.setPrefix("ns0")
listName.setPrefix("ns0")
However the last line above gives the following Error:
ERROR:suds.plugin:'NoneType' object has no attribute 'setPrefix'
So body
is None
itself. Clearly I am doing something wrong. Help me please.