SecureAuth cause - ShareplumRequestError: Shareplum HTTP Post Failed : 403 Client Error: Forbidden for url

Viewed 2081

We are trying to access sharepoint and we are succeeding depending on whether or not the specific sharepoint section is protected with "SecureAuth".

The program works fine if the url is not protected with "SecureAuth", but if this URL is protected with "SecureAuth" it returns this error. Is there any way to fix it?

We are using:

 from shareplum import Site
 from shareplum import Office365
 from shareplum.site import Version

 authcookie = Office365(sharepoint_address, username=sharepoint_user,\
                        password=sharepoint_user_pw).GetCookies()
 site = Site(f"https://myWeb.com/sites/{sharepoint_site}/", version=Version.v365, authcookie=authcookie)
 folder = site.Folder(sharepoint_folder) # here come the error

Depending of {sharepoint_site} its working or not.

Its the same error but its not related to that topic

2 Answers

It's not clear if the SharePoint that you need to access is OnPremises or Online (Office 365), but I'll share all possibilities and respective approaches:

If the SharePoint site address cotains the format https://[tenant].sharepoint.com/sites/BusinessAreaOfCompany, where [tenant] is a string that suggests reference of the company. This site hosted in an Office 365 environment; than, the code example above that you share (AND the user needs the minimal required permissions), is like this:

from shareplum import Site
from shareplum import Office365

authcookie = Office365('https://[tenant].sharepoint.com', username='username@[tenantdomain].com', password='password').GetCookies()
site = Site('https://[tenant].sharepoint.com/sites/BusinessAreaOfCompany', authcookie=authcookie)

Else, if the SharePoint Site url uses any company domain different of the TENANT address, for example https://xyz.company.com/sites/BusinessAreaOfCompany, the SharePoint is an OnPremises Environment, and uses NTLM or Kerberos for authenticate. The appropriate code approach example is (REMEMBER: the user needs the minimal required permissions):

from shareplum import Site
from requests_ntlm import HttpNtlmAuth

cred = HttpNtlmAuth('Username', 'Password')
site = Site('https://xyz.company.com/sites/BusinessAreaOfCompany', auth=cred)

Reference: SharePlum: Python + SharePoint

For me it was a language issue. Our sharepoint-filesystem is in german, so I changed from

'Shared Documents' to 'Freigegebene Dokumente'

in the folder path and everything works fine.

Related