roh*_*hak 1 python authentication sharepoint python-requests sharepoint-online
我可以完全访问我想连接到 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,
)
Run Code Online (Sandbox Code Playgroud)
为什么我收到错误代码 403 ?
HttpNtlmAuth应该通过 HTTP NTLM 身份验证使用,但SharePoint Online不支持该身份验证。
相反,您可以考虑Office365-REST-Python-Client 库。以下示例演示如何通过用户凭据进行身份验证并读取 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"]))
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
9701 次 |
| 最近记录: |