【问题标题】:SharePlum error : "Can't get User Info List"SharePlum 错误:“无法获取用户信息列表”
【发布时间】:2017-08-08 12:48:27
【问题描述】:

我正在尝试使用 SharePlum,它是 SharePoint 的 Python 模块,但是当我尝试连接到我的 SharePoint 时,SharePlum 会提示我这个错误:

回溯(最近一次通话最后一次):
文件“C:/Users/me/Desktop/Sharpoint/sharpoint.py”,第 13 行,在 site = Site(sharepoint_url, auth=auth)
init self.users = self 中的文件“C:\Users\me\AppData\Local\Programs\Python\Python36\lib\site-packages\shareplum\shareplum.py”,第 46 行。 GetUsers()
GetUsers 中的文件“C:\Users\me\AppData\Local\Programs\Python\Python36\lib\site-packages\shareplum\shareplum.py”,第 207 行引发异常(“无法获取用户信息列表”)
例外:无法获取用户信息列表

这是我写的非常短的代码:

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

这个错误似乎表明用户名/密码错误,但我很确定我的用户名/密码是正确的......

【问题讨论】:

    标签: python sharepoint


    【解决方案1】:

    好的,我似乎找到了解决问题的方法,这与我提供的 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%20folder 中,而不是在“正常” URL 中(如果是,它将像https://www.mysharepoint.com/Your/SharePoint/DocumentLibrary/myPersonnalFolder/)。

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

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

    我对 Sharepoint 还很陌生,所以我不确定这是否是其他人对这个问题的正确答案,比我更了解 Sharepoint 的人可以确认一下吗?

    【讨论】:

    • 砰,你应该接受你自己的答案;它节省了很多头痛。基本上,使用最低限度的共享点 URL,并将 URL 层次结构委托给shareplum.Site().List()shareplum 需要更好的实际用例文档
    【解决方案2】:

    我知道这不是您问题的实际解决方案,我只会添加评论,但它太长了,所以我将发布作为答案。

    我无法复制您的问题,但通过查看 shareplum.py 的源代码,您可以了解程序抛出错误的原因。在 shareplum.py 的第 196 行中,有 if 子句 (if response.status_code == 200:) 检查访问您的共享点 url 的请求是否成功(比它的状态码 200)以及请求是否失败(比它有一些其他状态码)它抛出异常(无法获取用户信息列表)。如果您想了解有关您的问题的更多信息,请转到您的 shareplum.py 文件(“C:\Users\me\AppData\Local\Programs\Python\Python36\lib\site-packages\shareplum\shareplum.py”)和在第 207 行之前添加此行 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")')。那么你的 shareplum.py 应该是这样的:

    # 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")
    

    现在再次运行您的程序,它应该会打印出它为什么不工作的原因。 我知道最好不要更改 Python 模块中的文件,但如果你知道你更改了什么,那么就没有问题,所以当你完成后,只需删除添加的行。

    此外,当您找到状态码时,您可以在线搜索,只需在 google 中输入或在 List_of_HTTP_status_codes 上搜索即可。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-06-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-11-20
      相关资源
      最近更新 更多