none
Upload Documents to Sharepoint 2016 from Python RRS feed

  • Question

  • Hello, 

    I'm trying to automatically upload a document to my Sharepoint document library with a python script but the script will not accept my URL for the site. 

    I can save the document locally, and I can navigate to the Sharepoint document library using the URL in Windows 10 file explorer by just pasting it in the path bar. Then I can paste in files and they will show up when I refresh the page. 

    This is the code for the python script:

    data = "String"
    print(type(data))
    
    
    filePath = 'C://Users//username//Desktop//mydocument.json'     # works fine
    #filePath = 'https://contoso.sharepoint.com/sites/mysite/Shared%20Documents/'   # error: path not found
    
    with open(filePath, 'w') as fp:
            fp.write(data)
    

    Why wont the python script upload using the URL?

    Can anyone try and get this to work?

    Thanks

    Tuesday, October 16, 2018 11:07 PM

All replies

  • Update - I think I figured out the correct URL

    To get the correct URL:

    1. Open the Sharepoint site Shared Documents in file explorer on your host machine

    2. Right-click a random file in the folder and click "create shortcut"

    3. Right-click on the shortcut that was just created and click "properties"

    4. The "Target: " will have a text box with the correct file path to use.

    Now when I try that file path in my python script I get a "permission denied" error when trying to upload a file. I believe I need to add the site to my trusted sites and select "automatically login"

    Friday, October 19, 2018 5:37 PM