python - 如何使用 OAuth2 访问 SharePoint 列表
问题描述
我有以下代码,我相信它适用于大多数共享点站点,但收到以下错误:
异常(“检查用户名/密码和根站点”)
from office365.runtime.auth.authentication_context import AuthenticationContext
from office365.sharepoint.client_context import ClientContext
url = 'https://company.sharepoint.com'
username = 'user123@company.com'
password = 'password'
listname = 'Test List'
ctx_auth = AuthenticationContext(url)
if ctx_auth.acquire_token_for_user(username, password):
ctx = ClientContext(url, ctx_auth)
web = ctx.web
sp_list = ctx.web.lists.get_by_title(listname)
items = sp_list.get_items()
ctx.load(items)
ctx.execute_query()
else:
print(ctx_auth.get_last_error())
我将如何操作此代码以确保我可以将 SharePoint 列表中的数据提取到 Python 中?
解决方案
我建议你检查Office365-REST-Python-Client
from office365.runtime.auth.authentication_context import AuthenticationContext
from 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
sp_list = ctx.web.lists.get_by_title(listname)
items = sp_list.get_items()
ctx.load(items)
ctx.execute_query()
# to do
else:
print ctx_auth.get_last_error()
推荐阅读
- python - 打印带有整数的 PyTorch 张量时如何设置精度?
- kubernetes - kubernetes 自动缩放错误custome metriccs
- javascript - ScrollMagic 动画在 Windows 笔记本电脑或 Android 手机中不起作用
- python - 为什么我的零列表会导致 IndexError?
- python - PyTesseract - 被水平白线打断的文本
- c - MPI_Gather 动态 2D 分配数组 - MPI C
- wordpress - 如何让我的 Wordpress 插件选项支持多语言?
- php - 如何在列表视图中显示 woocommerce 产品,没有图像
- json - 如何仅列出 API JSON 文件的特定项目?
- c# - 如何清除 Hackerrank 动态数组运行时错误?