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
Question Embedding a python file online Dreary35 0 197 Jun-10-2021, 05:05 PM
Last Post: Dreary35
  Authentication error when accessing Microsoft SharePoint klllmmm 3 2,618 Jun-10-2020, 07:46 AM
Last Post: nuffink
  unable to generate authentication key lokamaba 0 613 May-14-2020, 12:33 PM
Last Post: lokamaba
  need some help to do Vault authentication using python dspy9 0 496 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 972 Mar-20-2020, 06:56 AM
Last Post: buran
  user authentication in python saurabhc 1 914 Sep-15-2019, 11:59 AM
Last Post: jefsummers
  Pulling data from Sharepoint list gandiswapna0388 1 1,103 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