Upload/Download data to/from a sharepoint folder
Here is how to upload/download file to/from a sharepoint folder without having to use any convoluted authentication method.
import subprocess
import shutil
problem = False
url = 'https://site.sharepoint.com/path/to/your/folder'
#mount sharepoint as a network share
if subprocess.call(f'net use S: {url}', shell=True) != 0:
subprocess.call(r'net use S: /delete /y', shell=True)
if subprocess.call(f'net use S: {url}', shell=True) != 0:
problem = True
if not problem:
#do some stuff
shutil.copy("link_to_local_file","S:\\")
else:
print(f'Problem with accessing the Sharepoint site : {url}')
#unmount the network share
subprocess.call(r'net use S: /delete /y', shell=True)