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

时间:2018-07-02 07:33:02

标签: python sharepoint urllib2

我正在使用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打开器创建为:

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)

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

1 个答案:

答案 0 :(得分:3)

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

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

这里是一个类似的示例,用于获取网站中的所有列表并打印其标题

private void button1_Click(object sender, EventArgs e)
{

    info = textBox1.Text;
    this.Hide();
    BeginInvoke(new MethodInvoker(() =>
    {
        Gogo();
    }));
}

public void Gogo()
{
    Form1 frm = new Form1();
    frm.Show();
    frm.Text = info;
}