如何通过 UpdateListItems SOAP API 调试在 SharePoint 中创建列表项时出错? [英] How to Debug Error Creating List Item in SharePoint via UpdateListItems SOAP API?

查看:49
本文介绍了如何通过 UpdateListItems SOAP API 调试在 SharePoint 中创建列表项时出错?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在调试 SharePoint SOAP 调用以创建列表项时遇到了非常困难的时间.我发送的 SOAP 正文是:

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>

无论我做什么,我总是会返回一个 SoapServerException 异常,详细信息为值不在预期范围内".这是在我拥有完全访问权限的 SharePoint 网站上.这是一个新创建的列表,标题是唯一必需的属性.我如何找出问题所在?

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 required attribute. How do I figure out what the issue is?

FWIW,我对 GetList 和 GetListItems 等其他方法没有问题.我只是没有运气使用 UpdateListItems 添加新列表项.

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:在尝试第一次更新调用之前尝试设置 client.options.prettyxml = True.

TLDR: Try setting client.options.prettyxml = True before you try your first update call.

天哪,我一整天都在与一个明显相同的问题搏斗.假设您使用的是类似的 suds 版本(此处为 suds_jurko 0.5),我该如何更好地调试它?"的答案.在某种程度上,正在记录:

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)

在 sax 文档/元素(或与它们相邻)的某处存在一个错误,导致element.plain()"函数认为该元素为空.当 client.options.prettyxml 为 False 时,SoapClient.send() 尝试使用 sax 文档的 'plain()' 方法而不是 str() 方法.这样做的结果是元素被解析为空,导致 UpdateListItems 失败,并显示值不在预期范围内"错误.

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.

例如:

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>'

请注意,GetListItems() 方法对我也有效",因为 sax 在该 SOAP 调用中放置了一个空的查询元素,这在技术上没有问题.

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.

要解决此问题,请在调用第一个服务之前通过在某处添加 client.options.prettyxml = True 来强制 SoapClient.send() 使用漂亮"版本.

To workaround this, force SoapClient.send() to use the 'pretty' version by adding client.options.prettyxml = True somewhere before you invoke your first service.

我没有注意到这个错误,因为我显然在它被破坏之前检查了我的 SOAP 对象;打开日志显示最后一分钟的更改.

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)

这篇关于如何通过 UpdateListItems SOAP API 调试在 SharePoint 中创建列表项时出错?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆