我完全有权访问要连接到Microsoft.sharepoint.c0m网站列表的资源。
我想知道从python的共享点列表中提取或上传数据的最简单方法是什么?我收到此代码的错误代码403:
import requests
from requests_ntlm import HttpNtlmAuth
import urllib3
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
auth = HttpNtlmAuth('username', 'password')
r = requests.get("https://sharepoint.com/_api/Web/lists/GetByTitle('ListName')/items",
verify=False,
auth=auth,
)
为什么我收到错误代码403?
答案 0 :(得分:3)
HttpNtlmAuth应该通过HTTP NTLM身份验证来使用, SharePoint Online 中不支持。
相反,您可以考虑使用Office365-REST-Python-Client library。下面的示例演示如何通过用户凭据进行身份验证并读取SharePoint Online中的列表项:
from office365.runtime.auth.authentication_context import AuthenticationContext
ffrom office365.sharepoint.client_context import ClientContext
ctx_auth = AuthenticationContext(url)
if ctx_auth.acquire_token_for_user(username, password):
ctx = ClientContext(url, ctx_auth)
web = ctx.web
list_object = ctx.web.lists.get_by_title(listTitle)
items = list_object.get_items()
ctx.load(items)
ctx.execute_query()
for item in items:
print("Item title: {0}".format(item.properties["Title"]))