Python SharePlum错误:“;Can';“获取用户信息列表”;

Python SharePlum错误:“;Can';“获取用户信息列表”;,python,sharepoint,Python,Sharepoint,我正在尝试使用SharePoint的Python模块,但当我尝试连接到SharePoint时,SharePlum会引发以下错误: 回溯(最近一次呼叫最后一次): 文件“C:/Users/me/Desktop/Sharpoint/Sharpoint.py”,第13行,位于site=site(sharepoint\u url,auth=auth) 文件“C:\Users\me\AppData\Local\Programs\Python36\lib\site packages\shareplum\sh

我正在尝试使用SharePoint的Python模块,但当我尝试连接到SharePoint时,SharePlum会引发以下错误:

回溯(最近一次呼叫最后一次):
文件“C:/Users/me/Desktop/Sharpoint/Sharpoint.py”,第13行,位于site=site(sharepoint\u url,auth=auth)
文件“C:\Users\me\AppData\Local\Programs\Python36\lib\site packages\shareplum\shareplum.py”,第46行,位于initself.Users=self.GetUsers() 文件“C:\Users\me\AppData\Local\Programs\Python36\lib\site packages\shareplum\shareplum.py”,第207行,在GetUsers引发异常(“无法获取用户信息列表”)
异常:无法获取用户信息列表

以下是我编写的非常简短的代码:

auth = HttpNtlmAuth(username, password)  
site = Site(sharepoint_url, auth=auth)

此错误似乎表明用户名/密码不正确,但我很确定我的用户名/密码是正确的…

我知道这不是解决您问题的实际方法,我只想添加注释,但太长了,所以我将作为答案发布


我无法复制您的问题,但通过查看shareplum.py的源代码,您可以了解程序抛出错误的原因。在shareplum.py的第196行中有if子句(
if response.status_code==200:
),它检查访问sharepoint url的请求是否成功(状态代码为200),如果请求失败(状态代码为200),则抛出异常(无法获取用户信息列表)。如果您想了解有关您的问题的更多信息,请转到shareplum.py文件(“C:\Users\me\AppData\Local\Programs\Python\Python36\lib\site packages\shareplum\shareplum.py”),并添加以下行
print('{}{}{}错误:{}用于url:{}'。格式(response.status\u代码,'Client'*(400好的,看来我找到了解决问题的方法,是关于我给出的Sharepoint URL。
如果我们举这个例子:
https://www.mysharepoint.com/Your/SharePoint/DocumentLibrary

您必须删除最后一部分:
/DocumentLibrary

为什么要精确地删除此部件?
事实上,当你深入到Sharepoint中时,你的url看起来就像:
https://www.mysharepoint.com/Your/SharePoint/DocumentLibrary/Forms/AllItems.aspx?RootFolder=%2FYour%2FSharePoint%2DocumentLibrary%2FmyPersonnalFolder&FolderCTID=0x0120008BBC54784D92004D1E23F557873CC707&View=%7BE149526D%2DFD1B%2D4BFA%2DAA46%2D90DE0770F287%7D

您可以看到路径的右侧位于
RootFolder=%2FYour%2FSharePoint%2DocumentLibrary%2Fmy%20personnal%20文件夹中,而不再位于“正常”URL中(如果是,则会像
https://www.mysharepoint.com/Your/SharePoint/DocumentLibrary/myPersonnalFolder/

您必须删除的是“正常”URL的结尾,因此在本例中,
/DocumentLibrary

因此,我在SharePlum中输入的正确Sharepoint URL将是
https://www.mysharepoint.com/Your/SharePoint/


我对Sharepoint非常陌生,所以我不确定这对其他人来说是否是这个问题的正确答案,也许比我更了解Sharepoint的人可以确认吗?

bang,你应该接受自己的答案;这避免了太多的头痛。基本上,使用最简单的Sharepoint URL,并将URL层次结构委托给
shareplum.Site().List()
。需要稍微好一点的文档才能用于实际用例
# Parse Response
    if response.status_code == 200:
        envelope = etree.fromstring(response.text.encode('utf-8'))
        listitems = envelope[0][0][0][0][0]
        data = []  
        for row in listitems:
            # Strip the 'ows_' from the beginning with key[4:]
            data.append({key[4:]: value for (key, value) in row.items() if key[4:]})

        return {'py': {i['ImnName']: i['ID']+';#'+i['ImnName'] for i in data},
                'sp': {i['ID']+';#'+i['ImnName'] : i['ImnName'] for i in data}}
    else:
        print('{} {} Error: {} for url: {}'.format(response.status_code, 'Client'*(400 <= response.status_code < 500) + 'Server'*(500 <= response.status_code < 600), response.reason, response.url))
        raise Exception("Can't get User Info List")