首页 > 解决方案 > 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 页面上提出了这个问题。问题可以在这里找到

标签: pythonpython-3.xodataoffice365api

解决方案


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

我希望它可以帮助。


推荐阅读