簡體   English   中英

Python:創建具有多選值的列表。 錯誤:找到一個開放的集合屬性。 在 OData 中,不支持開放集合屬性

[英]Python: Create list with Multi-choice value. Error: An open collection property was found. In OData, open collection properties are not supported

我正在使用以下代碼將項目添加到 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 圖書館的 Github 頁面上提出了這個問題。 問題可以在這里找到

我不是使用 python 和 sharepoint API 的專家,但您似乎正在嘗試將項目添加到列表中並同時添加選擇。 我相信這個列表應該與選項字段一起存在,添加時您只需添加您為添加的項目選擇的選項。

我希望它可以幫助。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM