Search code examples
pythonsharepointsharepoint-list

Python to sharepoint Forbidden for URL


I was looking to connect to my corporate sharepoint list but for testing purposes i am using this dummy templatei created.

from shareplum import Site
from requests_ntlm import HttpNtlmAuth

cred = HttpNtlmAuth('email I use to login', 'password')


site = Site('https://griffithcollege628.sharepoint.com/sites/Sharepointtest/', auth=cred)
sp_list = site.List('list name')

list_data = sp_list.GetListItems()

But when i get to this line:

site = Site('https://griffithcollege628.sharepoint.com/sites/Sharepointtest/', auth=cred)

I get the following error:

Shareplum HTTP Post Failed : 403 Client Error: Forbidden for url: https://griffithcollege628.sharepoint.com/sites/Sharepointtest//_vti_bin/lists.asmx

enter image description here


Solution

  • I have tried with the below method and I am able to get the list items. Let me know if it is working.

    from shareplum import Office365, Site
    from shareplum.site import Version
    
    server_url = "https://my_page.sharepoint.com/"
    site_url = server_url + "sites/my_site_name"
    authcookie = Office365(server_url, username=Username,password=Password).GetCookies() #here username is my mail ID
    site = Site(site_url, version=Version.v365, authcookie=authcookie)
    sp_list = site.List('my_list_name')
    sp_data = sp_list.GetListItems()