SharePlum error : “Can't get User Info List”

て烟熏妆下的殇ゞ 提交于 2021-02-08 12:27:12

问题


I'm trying to use SharePlum which is a Python module for SharePoint but when I try to connect to my SharePoint, SharePlum raises me this error:

Traceback (most recent call last):
File "C:/Users/me/Desktop/Sharpoint/sharpoint.py", line 13, in site = Site(sharepoint_url, auth=auth)
File "C:\Users\me\AppData\Local\Programs\Python\Python36\lib\site-packages\shareplum\shareplum.py", line 46, in init self.users = self.GetUsers()
File "C:\Users\me\AppData\Local\Programs\Python\Python36\lib\site-packages\shareplum\shareplum.py", line 207, in GetUsers raise Exception("Can't get User Info List")
Exception: Can't get User Info List

Here is the very short code that I have written:

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

This error seems to indicate bad username/password but I'm pretty sure that the one I have are correct...


回答1:


Ok, it seems that I found the solution for my problem, it's about the Sharepoint URL that I gave. If we take this example : https://www.mysharepoint.com/Your/SharePoint/DocumentLibrary
You have to remove the last part : /DocumentLibrary.

Why remove this part precisely ?
In fact, when you go deep enough in your Sharepoint, your url will look like something like : https://www.mysharepoint.com/Your/SharePoint/DocumentLibrary/Forms/AllItems.aspx?RootFolder=%2FYour%2FSharePoint%2DocumentLibrary%2FmyPersonnalFolder&FolderCTID=0x0120008BBC54784D92004D1E23F557873CC707&View=%7BE149526D%2DFD1B%2D4BFA%2DAA46%2D90DE0770F287%7D

You can see that the right of the path is in RootFolder=%2FYour%2FSharePoint%2DocumentLibrary%2Fmy%20personnal%20folder and not in the "normal" URL anymore (if it were, it will be like that https://www.mysharepoint.com/Your/SharePoint/DocumentLibrary/myPersonnalFolder/).

What you have to remove is the end of the "normal" URL so in this case, /DocumentLibrary.

So my correct Sharepoint URL to input in SharePlum will be https://www.mysharepoint.com/Your/SharePoint/

I'm pretty new to Sharepoint so I'm not really sure that this I the right answer to this problem for the others persons, may someone who know Sharepoint better than me can confirm ?




回答2:


I know this is not actual solution for your problem and I would add just comment but it was too long so I will post as answer.

I can't replicate your issue, but by looking into source code of shareplum.py you can see why program throws the error. In line 196 of shareplum.py there is if clause (if response.status_code == 200:) which checks if the request to access your sharepoint url was successful (than it has status code 200) and if request failed (than it has some other status code) than it throws exception (Can't get User Info List). If you want to find out more about your problem go to your shareplum.py file ("C:\Users\me\AppData\Local\Programs\Python\Python36\lib\site-packages\shareplum\shareplum.py") and add this line print('{} {} Error: {} for url: {}'.format(response.status_code, 'Client'*(400 <= response.status_code < 500) + 'Server'*(500 <= response.status_code < 600), response.reason, response.url)) before line 207 ('raise Exception("Can't get User Info List")'). Then your shareplum.py should look like this:

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

Now just run your program again and it should print out why it isn't working. I know it is best not to change files in Python modules, but if you know what you change then there is no problem so when you are finished just delete the added line.

Also when you find out status code you can search it online, just type it in google or search on List_of_HTTP_status_codes.



来源:https://stackoverflow.com/questions/45568823/shareplum-error-cant-get-user-info-list

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!