无法使用shareplum将列表项“添加”到SharePoint列表。

huangapple go评论60阅读模式
英文:

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.

huangapple
  • 本文由 发表于 2023年3月7日 07:37:32
  • 转载请务必保留本文链接:https://go.coder-hub.com/75656786.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定