Efficient scripting with Python & SharePoint in Microsoft Office 365
A Python script to automate uploading to Sharepoint
Python scripting is a great way to automate many processes that you use daily such as updating an excel spreadsheet with data from an API, sending out daily PDF reports, or uploading files to a google cloud.
Computers are incredibly efficient at carrying out repeated tasks, and we can utilize this power with scripts and cron jobs. For example, when regularly uploading a Python-produced report or CSV file on a Monday Morning to Sharepoint/Onedrive to provide updated progress reports.
Authentication
Authenticating with a password and user email is necessary to access the shared file directory in SharePoint sites. Which can prove to be tricky if your account has 2-factor authentication enabled; this will raise an Exception:
Exception('Error authenticating against Office 365.')
So for this to work and bypass any authentication errors, you can create a new password specifically for executing the script.
Creating a new App Password in Microsoft 365
Log into your Office 365 account → View Account → Security info|
You should see the methods you use to sign in to your account. You can then click 'Add…