I'm having a really tough time debugging a SharePoint SOAP call to create a list item. The SOAP body I'm sending is:
<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>{35BC2CB3-D2FB-4D47-B711-7502819D6E2B}</ns1:listName>
<ns1:updates>
<Batch OnError="Continue" ListVersion="1">
<Method ID="1" Cmd="New">
<Field Name="ID">New</Field>
<Field Name="Title">Test Summary</Field>
</Method>
</Batch>
</ns1:updates>
</ns1:UpdateListItems>
</ns0:Body>
</SOAP-ENV:Envelope>
No matter what I do, I always get back a SoapServerException with, "Value does not fall within the expected range," as the detail. This is on a SharePoint site that I have full access to. It's a newly created list with Title as the only开发者_如何学C required attribute. How do I figure out what the issue is?
FWIW, I have no problem with other methods like GetList and GetListItems. I'm just having no luck using UpdateListItems to add a new list item.
TLDR: Try setting client.options.prettyxml = True
before you try your first update call.
Holy hell, I've been wrestling with an apparently identical issue for a whole day. Assuming you were using a similar suds version (suds_jurko 0.5 here), the answer to "how do I better debug this?" to a degree, was logging:
import logging
logging.basicConfig(level=logging.INFO)
logging.getLogger('suds.client').setLevel(logging.DEBUG)
logging.getLogger('suds.transport').setLevel(logging.DEBUG)
There is a bug nestled somewhere in the sax document/elements (or adjacent to them) that was causing the "element.plain()" function to think the element was empty. When client.options.prettyxml is False, SoapClient.send() tries to use the 'plain()' method of the sax Document instead of the str() method. The result of this was that the element was getting parsed as empty, causing the UpdateListItems to fail with the "Value does not fall within the expected range," error.
ex:
MESSAGE:
b'<?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>B5E50422-D16B-4C5F-AE19-CFBE943C6F3F</ns1:listName>
<updates/>
</ns1:UpdateListItems>
</ns0:Body>
</SOAP-ENV:Envelope>'
Note that the GetListItems() methods 'worked' for me as well, because the sax was putting an empty query element in that SOAP call, which was technically fine.
To workaround this, force SoapClient.send() to use the 'pretty' version by adding client.options.prettyxml = True
somewhere before you invoke your first service.
I had not noticed the fault, because I was apparently checking my SOAP object before it got mangled; turning on the logging revealed the last minute alteration.
(I realize this is an old question, not sure if that's frowned upon; but it was the closest I was able to find to my actual problem earlier and felt it deserved an answer)
I had this issue myself.
This is the code I used and it seems to work:
batch = Element('Batch').append(Attribute('OnError', 'Return'))
batch.append(Attribute('ListVersion', '1'))
method = Element('Method').append(Attribute('ID', '1'))
method.append(Attribute('Cmd', 'Update'))
method.append(Element('Field').append(Attribute('Name', 'ID')).setText(1))
method.append(Element('Field').append(Attribute('Name', 'Title')).setText('Just Changed It23223'))
batch.append(method)
updates = Element('ns1:updates')
updates.append(batch)
client.service.UpdateListItems('Test', updates)
Please ensure your list ID is correct and fields are using internal names only for the list you are adding item.
Try putting your method inside try catch block. Put below section above catch block to have further details for the exception.
catch (soapserver.soapserverexception ex)
{
console.writeline(ex.detail.innertext);
}
精彩评论