Python Forum
SharePoint Online/365 authentication using .cer file
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
SharePoint Online/365 authentication using .cer file
#1
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)
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Updating sharepoint excel file odd results cubangt 1 754 Nov-03-2023, 05:13 PM
Last Post: noisefloor
  Trying to access excel file on our sharepoint server but getting errors cubangt 0 773 Feb-16-2023, 08:11 PM
Last Post: cubangt
  REST API x.509 authentication crossover 1 2,355 Feb-15-2022, 12:21 AM
Last Post: snippsat
Question Embedding a python file online Dreary35 0 1,477 Jun-10-2021, 05:05 PM
Last Post: Dreary35
  Authentication error when accessing Microsoft SharePoint klllmmm 3 10,097 Jun-10-2020, 07:46 AM
Last Post: nuffink
  Using online python for course, How do I open a File that's a link? WhatsupSmiley 1 2,499 Mar-20-2020, 06:56 AM
Last Post: buran
  Pulling data from Sharepoint list gandiswapna0388 1 2,563 Jul-17-2019, 08:35 AM
Last Post: perfringo

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020