Python-如何在不访问root的情况下访问SharePoint网站



我正试图从一个URL类似的网站上的HTML表中读取数据https://mysharepoint.sharepoint.com/sites/mySite/sitepages/tables

我只能访问";mySite";地点我试过像他们的文档一样使用shareplum:

from shareplum import Site
from shareplum import Office365
authcookie = Office365('https://abc.sharepoint.com', username='username@abc.com', password='password').GetCookies()
site = Site('https://abc.sharepoint.com/sites/MySharePointSite/', authcookie=authcookie)

但我随后得到以下错误:;requests.exceptions.HTTPError:403客户端错误:url被禁止:https://abc.sharepoint.com/sites/MySharePointSite/_vti_bin/lists.asmx">

我猜这正是因为我无法访问根网站,但我也尝试过这样做:

authcookie = Office365('https://abc.sharepoint.com/sites/MySharePointSite/', username='username@abc.com', password='password').GetCookies()
site = Site('https://abc.sharepoint.com/sites/MySharePointSite/', authcookie=authcookie)

但这也产生了同样的错误。

有人知道向shareplum指定我想在特定网站上使用凭据的方法吗,或者不完全使用shareplum的方法吗?

SharePlum GitHub repo上的Issue#105建议了一个解决方法:在shareplum/request_help.py中,注释掉post函数中的以下行(v0.5.1为ln.17(:response.raise_for_status()

这将导致接受403返回状态,这是因为您无法访问根站点。对我来说,这解决了问题,因为身份验证实际上是成功的,并且我可以使用返回的authcookie来处理SharePoint子网站。

相关内容

最新更新