python - 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 的专家,但您似乎正在尝试将项目添加到列表中并同时添加选项。我相信这个列表应该与选项字段一起存在,添加时您只需添加您为添加的项目选择的选项。
我希望它可以帮助。
推荐阅读
- optimization - 使用 GEKKO 对大量变量、边界和约束进行优化
- java - firestore 快照监听器的生命周期和定价之间有什么关系?
- spring - 连接到 Okta 时在 Webclient 上获取 readAddress() 异常
- javascript - 即使使用了 escapeCharacter 函数,RegExp 值仍然不能与 .match 一起使用
- flutter - 是否可以将原生 sdks 添加到 Flutter 应用程序并在 Flutter 应用程序和原生 SDK 之间架起一座桥梁?
- javascript - 使用 Socket.io 的 Websocket 连接中出现无法解释的延迟,页面加载后正好 10 秒
- python - TensorFlow 的线程
- php - bootstrap 4的折叠导航栏
- python - 在 Python 和 Plotly 中更改地图 Choroplethmapbox 上的值的菜单或按钮
- google-bigquery - 将 BQ 模式更改部署到 QA 和生产项目