gpt4 book ai didi

python - 无法使用 python 访问共享点列表

转载 作者:太空宇宙 更新时间:2023-11-04 00:15:29 24 4
gpt4 key购买 nike

我正在使用 python-sharepoint 从我的 sharepoint 帐户访问数据。但我总是收到 urllib2.HTTPError: HTTP Error 403: Forbidden 错误。我正在关注 this github link .这是我的代码:

from sharepoint import SharePointSite, basic_auth_opener
server_url = 'https://myServerUrl.sharepoint.com/'
site_url = server_url + 'sites/test'
username = 'myUsername.onmicrosoft.com'
password = 'myPassword'

opener = basic_auth_opener(server_url, username, password)
site = SharePointSite(site_url, opener)
for sp_list in site.lists:
print (sp_list)

我还尝试将 urllib2 opener 创建为:

from sharepoint import SharePointSite
from ntlm import HTTPNtlmAuthHandler
import urllib2

password_manager = urllib2.HTTPPasswordMgrWithDefaultRealm()
password_manager.add_password(None, server_url, username, password)
auth_handler = HTTPNtlmAuthHandler.HTTPNtlmAuthHandler(password_manager)
opener = urllib2.build_opener(auth_handler)

site = SharePointSite(site_url, opener)
for sp_list in site.lists:
print (sp_list)

但它又给出了同样的错误。任何解决方案将不胜感激。

最佳答案

SharePoint Online 不支持 BasicNTLM 身份验证方法,这使得 python-sharepoint不是这里的最佳选择。

相反,我建议您尝试一下 Office365-REST-Python-Client支持 Office 365/SharePoint Online。

下面是获取站点中所有列表并打印其标题的类似示例

ctx_auth = AuthenticationContext(url='https://contoso.sharepoint.com')
if ctx_auth.acquire_token_for_user(username='jdoe@contoso.onmicrosoft.com'],
password='--password--'):

ctx = ClientContext(settings['url'], ctx_auth)
lists = ctx.web.lists
ctx.load(lists)
ctx.execute_query()
for l in lists:
print(l.properties["Title"])

关于python - 无法使用 python 访问共享点列表,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51131125/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com