How to debug the error Creating a list item in SharePoint using the SOAP API UpdateListItems API?

I have very hard debugging a SharePoint SOAP call to create a list item. The SOAP body I am 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 return a SoapServerException with: "The value is not in the expected range", as a detail. This is on a SharePoint site where I have full access. This is a newly created list with a caption as the only required attribute. How to find out what the problem is?

FWIW, I have no problem with other methods like GetList and GetListItems. I just have nothing to use UpdateListItems to add a new list item.

+1
source share
3 answers

TL; DR: try setting client.options.prettyxml = True before trying your first update call.

Holy hell, I struggled with an apparently identical problem all day. Assuming you used a similar version of suds (suds_jurko 0.5 here), the answer to the question is "how best to debug this?". to some extent, it was recorded:

 import logging logging.basicConfig(level=logging.INFO) logging.getLogger('suds.client').setLevel(logging.DEBUG) logging.getLogger('suds.transport').setLevel(logging.DEBUG) 

There is an error in the sax / elements file (or next to it) that calls the element.plain () function to consider the element empty. When client.options.prettyxml is False, SoapClient.send () tries to use the plain () method for the sax file instead of the str () method. The result of this was that the element was parsed as empty, which caused UpdateListItems to crash with the error "The value does not fall within the expected range."

Example:

 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 because the saxophone placed an empty request element in this SOAP request that was technically accurate.

To get around this, make SoapClient.send () use the "pretty" version by adding client.options.prettyxml = True somewhere before you call the first service.

I did not notice the error, because I apparently checked my SOAP object before it was crippled; the inclusion of the journal led to a change in the last minute.

(I understand that this is an old question, not sure if it frowned, but it was the closest that I could find in my real problem earlier and felt that he deserved an answer)

+3
source

I had this problem.

This is the code I used and it works:

 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) 
+1
source

Make sure your list id is correct and the fields use internal names only for the list you add.

Try putting your method inside a catch try block. Place the section below the catch block for more information about this exception.

 catch (soapserver.soapserverexception ex) { console.writeline(ex.detail.innertext); } 
0
source

Source: https://habr.com/ru/post/1347872/


All Articles