Python Forum
SharePoint Online/365 authentication using .cer file - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: SharePoint Online/365 authentication using .cer file (/thread-30823.html)



SharePoint Online/365 authentication using .cer file - mart79 - Nov-08-2020

All,

I want to access our corporate SharePoint Online/365 site to collect information from our lists and/or libraries.
For this I have a cer file but, I need some help setting up the code to access the list/library using Python.

I managed to get it working for one of our older sites, which runs on SharePoint 2013, see below. But how do I set up something similar for SharePoint Online/365?

import requests
from requests_negotiate_sspi import HttpNegotiateAuth
from requests.exceptions import HTTPError
from requests.exceptions import Timeout
import xmltodict

# certificate location
cert = "[local folder]\\file.cer"

# site
site = 'https://[sharepoint site]'

# library
lib = '[library]'

path = r"{}_api/web/lists/GetByTitle('{}')/items?".format(site, lib)

try:
    # timeout = 2 seconds for establishing connection to server, 5 seconds to receive data from server
    response = requests.get(
        path,
        auth=HttpNegotiateAuth(),
        verify=cert, timeout=(2, 5))

    # raise error if applicable (eg. 404 etc.)
    response.raise_for_status()

except Timeout:
    print('The request timed out')
except HTTPError as http_err:
    print(f'HTTP error occurred: {http_err}')
except Exception as err:
    print(f'Other error occurred: {err}')

data_xml = xmltodict.parse(response.content)