Excel file corrupted after uploading to Sharepoint with Python RRS feed

  • Question

  • I am trying to upload an .xlsx file from a local folder to Sharepoint with a PUT request from the Requests module in Python. The file will appear in my Shared Documents folder, which is where I want it to be, but when I try to open the file, I get a message saying, "The workbook that you selected cannot be opened. The workbook may be in an unsupported file format, or it may be corrupt. Would you like to try and open this file in Excel?"

    I have researched this problem, and many forums that I've found have said that a common problem is that there's a space before a ^ symbol in the file somewhere, but at the moment, for testing purposes, I'm just trying to upload a completely blank file with absolutely nothing in it.

    Any advice or insight to my problem would be greatly appreciated!

    • Edited by Lucariko Tuesday, June 10, 2014 10:13 PM
    Tuesday, June 10, 2014 4:00 PM

All replies

  • When you say a "blank" file do you mean an empty Excel workbook or simply a file with a .xlsx file extension and a size of 0 bytes? The message you are seeing is similar to the message I get when I test with a file with 0 bytes.

    If this is the case for you, try again using a working Excel file.

    Tuesday, June 10, 2014 7:10 PM
  • I meant an empty Excel workbook, but I created a brand-new .xlsx file with a few cells with text in them, and I still got the same message. 

    Also, I tried manually uploading it to sharepoint (when I say manually, I mean that I clicked the "upload document" button on sharepoint and uploaded the file that way), then I can access and open the file just fine. I don't know if that helps to try and pinpoint the problem at all. 

    Tuesday, June 10, 2014 8:22 PM
  • Thank you for clarifying. :)

    Sounds like perhaps an issue with the HTTP PUT. I found your post on stackoverflow, there you have the following code:

    files = {'file': ('Test.xlsx', open('Test.xls', 'rb'), 'application/', {'Expires': '0'})}
    myFile = requests.put('http://linkToMySharepoint/Test.xlsx', files=files, auth=auth)

    I noticed the mime type you've specified is for a .xls file and not the newer .xlsx xml formatted file type.

    According to another stackoverflow post the mime type for .xlsx is:


    Will you please try this and see if the situation improves?

    Tuesday, June 10, 2014 8:50 PM
  • Ok, I tried the new mime type, and it still gives the same message. 
    Tuesday, June 10, 2014 9:58 PM
  • Were you able to solve this problem? I'm having the same issue.
    Friday, November 18, 2016 7:56 PM