4

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

Enrique Benito Casado
  • 1,914
  • 1
  • 20
  • 40
  • The sites that you try to connect are in Onpremises Environment ou Office 365? – Antonio Leonardo Aug 19 '21 at 18:28
  • @AntonioLeonardo Unfortunetly I dont know.. cause it a sharepoint for my Company..but I work in a Company with thousands of employees and that information is not accesible to me. – Enrique Benito Casado Aug 23 '21 at 07:16
  • Could it be that the `sharepoint_user` you are using does not have the appropriate permissions? 403 means the request is coming in nicely, but the client is not allowed to do it. A cursory look here: https://martinnoah.com/sharepoint-rest-api-with-python.html#.YSNa6dMzZTY suggests you need to do some backend setup – GregK Aug 23 '21 at 08:23

2 Answers2

4

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

Antonio Leonardo
  • 1,805
  • 1
  • 8
  • 18
2

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.

Phulc
  • 21
  • 2