英文:
Cannot "Add" List Item to SharePoint List using shareplum
问题
I am trying to update a Sharepoint list using shareplum. I am able to read information but for some reason I am not able to add a new list item. What is going wrong here?
from shareplum import Site
from requests_ntlm import HttpNtlmAuth
# variables
username = "myusername"
password = "mypassword"
site_url = "https://mycompansharepointsite.org/sites"
domain = "myCompanyDomain"
my_list_name = "listTitle"
my_data = [{
'Project_Field': 'TESTING'
}]
cred = HttpNtlmAuth(f'{domain}\\{username}', password)
site = Site(site_url, auth=cred)
mylist = site.List(my_list_name, exclude_hidden_fields=True)
incoming_list.UpdateListItems(data=my_data, kind='Update')
For example, after importing the library and declaring the variables to log me in, these lines work to read the Sharepoint list:
sp_list = site.List(my_list_name)
data = sp_list.GetListItems()
print(data)
I've thought maybe I need to use a different library like Office365-REST-Client but I thought, since I finally figured out how to get this far to read a Sharepoint list using shareplum, I would exhaust my resources before going down another rabbit hole.
英文:
I am trying to update a Sharepoint list using shareplum. I am able to read information but for some reason I am not able to add a new list item. What is going wrong here?
from shareplum import Site
from requests_ntlm import HttpNtlmAuth
# variables
username = "myusername"
password = "mypassword"
site_url = "https://mycompansharepointsite.org/sites"
domain = "myCompanyDomain"
my_list_name = "listTitle"
my_data = [{
'Project_Field': 'TESTING'
}]
cred = HttpNtlmAuth(f'{domain}\\{username}', password)
site = Site(site_url, auth=cred)
mylist = site.List(my_list_name, exclude_hidden_fields=True)
incoming_list.UpdateListItems(data=my_data, kind='Update')
For example, after importing the library and declaring the variables to log me in, these lines work to read the Sharepoint list:
sp_list = site.List(my_list_name)
data = sp_list.GetListItems()
print(data)
I've thought maybe I need to use a different library like Office365-REST-Client but I thought, since I finally figured out how to get this far to read a Sharepoint list using shareplum, I would exhaust my resources before going down another rabbit hole.
答案1
得分: 1
我没有使用过shareplum,但我确定你需要更新my_data变量,包括类型规范,如下所示:
my_data = [{
"__metadata": {"type": "SP.Data.LISTNAMEListItem"},
'Project_Field': 'TESTING'
}]
将LISTNAME替换为my_list_name变量。
英文:
I haven't used shareplum but I am sure you need to update the my_data variable to include the type specification like below:
my_data = [{
"__metadata": {"type": "SP.Data.LISTNAMEListItem"},
'Project_Field': 'TESTING'
}]
replace LISTNAME with the my_list_name variable.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论