Python:创建具有多选值的列表.错误:找到打开的集合属性.在 OData 中,不支持打开集合属性



我使用以下代码将项目添加到SharePoint列表:

from office365.runtime.auth.authentication_context import AuthenticationContext
from office365.runtime.client_request import ClientRequest
from office365.runtime.utilities.request_options import RequestOptions
from office365.sharepoint.client_context import ClientContext
app_settings = {
'url': 'url',
'client_id': 'clientid',
'client_secret': 'secret'
}
context_auth = AuthenticationContext(url=app_settings['url'])
context_auth.acquire_token_for_app(client_id=app_settings['client_id'], client_secret=app_settings['client_secret'])
ctx = ClientContext(app_settings['url'], context_auth)
print("Create list item example...")
list_object = ctx.web.lists.get_by_title("listtitle")
item_properties = {'__metadata': {'type': 'SP.List'}, 'Title': 'Task Created by Python Script',
'CategoryDescription': 'This is a test Task created by Python script with the help of Office 365 library.'}

我可以使用上面的代码成功地将项目添加到列表中。

现在,当我尝试使用如下所示的多项选择值传递相同的方法时,它不起作用

item_properties = {'__metadata': {'type': 'SP.List'}, 'Title': '01 Task Created by Python Script', 'CategoryDescription': 'This is a test Task created by Python script with the help of Office 365 library.'
'ChoiceField':{
'__metadata' : {'type' : 'Collection(Edm.String)' },
'results': ['value 1', 'value 2']
}
}

使用上述方法运行时,收到以下错误:

An open collection property 'ChoiceField' was found. In OData, open collection properties are not supported.", "400 Client Error: Bad Request for url:..."

没有运气找到解决方案。有人可以帮助我解决问题吗?

更新:我什至在Python office-365 libraray的Github页面上提出了这个问题。问题可以在这里找到

我不是使用 python 和 sharepoint API 的专家, 但似乎您正在尝试将项目添加到列表中,同时添加选项。 我相信这个列表应该存在选择字段,在添加时,您只需添加为添加的项目选择的选项。

我希望它能有所帮助。

最新更新