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
  sharepoint: Access has been blocked by Conditional Access policies CAD79 0 2,214 Jul-12-2024, 09:36 AM
Last Post: CAD79
  How to get all items in SharePoint recycle bin by using sharepy library in Python? QuangHuynh 2 1,554 Apr-10-2024, 03:09 PM
Last Post: SandraYokum
  Updating sharepoint excel file odd results cubangt 1 2,085 Nov-03-2023, 05:13 PM
Last Post: noisefloor
  Trying to access excel file on our sharepoint server but getting errors cubangt 0 1,497 Feb-16-2023, 08:11 PM
Last Post: cubangt
  REST API x.509 authentication crossover 1 4,418 Feb-15-2022, 12:21 AM
Last Post: snippsat
Question Embedding a python file online Dreary35 0 1,946 Jun-10-2021, 05:05 PM
Last Post: Dreary35
  Authentication error when accessing Microsoft SharePoint klllmmm 3 12,846 Jun-10-2020, 07:46 AM
Last Post: nuffink
  unable to generate authentication key lokamaba 0 2,030 May-14-2020, 12:33 PM
Last Post: lokamaba
  need some help to do Vault authentication using python dspy9 0 1,855 Apr-15-2020, 07:22 PM
Last Post: dspy9
  Using online python for course, How do I open a File that's a link? WhatsupSmiley 1 3,108 Mar-20-2020, 06:56 AM
Last Post: buran

Forum Jump:

User Panel Messages

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