Accessing company Sharepoint via Python to modify Excel files

I wrote a small script that goes through a bunch of folders and consolidates excel files.

Now I would like to use this script with files stored in our company sharepoint. Since getting support from our IT is not an option and I am looking to do this myself. I seem to get stuck at the authentication part though. Our sharepoint uses the windows credentials to connect to it, I dont have more information.

Any pointers would be helpful, I am gonna list some methods that I tried so far. Usually I get Error 401.

https://stackoverflow.com/questions/25764595/accessing-sharepoint-site-in-python-with-windows-authentication

I tried this code:

import requests
from requests_ntlm import HttpNtlmAuth


I dont know where to go from here, any pointers or ways to find out more information what type of authentication my sharepoint has would already be helpful.

If you are using SharePoint file libraries rather than lists you should just be able to give the server path to the file library as the folder path, instead of bothering with any SharePoint APIs.

For instance if your SharePoint site is SharePoint.Company.net/sites/sitename/LibraryName your server path to that Library might (as an example with SSL) be \\SharePoint.Company.net@SSL\sites\sitename\LibraryName.

This works on my company's.

The easiest way to get the correct path to use is to go to the library in IE and use the open with explorer button. Then use that URL to map the drive to a letter and the mapped details will then give the details you need. Then you can just reference that path like a normal folder path as if it was part of your local drives.

• @Robert Lindgren Thanks for the reply. But this would propably also mean, that this script would already require an active sharepoint connection right? As in, I have to be logged in and at my pc to run this? – Tim Aug 22 '18 at 15:28
• This worked well for me. I used forward slashes. – stevepastelan May 28 '20 at 21:02

The other two options you could give a try are Kerberos or Basic Authentication:

Kerberos:

import requests
from requests_negotiate_sspi import HttpNegotiateAuth

cert = 'path\to\certificate.cer'

response = requests.get(
r'http://mysharepoint.com/_api',
auth=HttpNegotiateAuth(),
verify=cert)

print(response.status_code)


Basic:

import requests
from requests.auth import HTTPBasicAuth

cert = 'path\to\certificate.cer'
user = 'DOMAIN\\User'