I am trying to download an excel file from a OneDrive location. My code works okay to get the file, but the file is corrupt (I get an error message):
import urllib2
data = urllib2.urlopen("enter url here")
with open('C:\\Video.xlsx', 'wb') as output:
output.write(data.read())
output.close()
print "done"
I use the guest access to the excel file so that I don't have to work with authentication. The resulting file seems to be 15KB, the original is 22KB.
You can't just download the Excel file directly from OneDrive using a URL. Even when you would share the file without any authorization, you'll probably still get a link to an intermediate HTML page, rather than the Excel binary itself.
To download items from your OneDrive, you'll first need to authenticate and then pass the location of the file you're after. You'll probably want to use the OneDrive REST API. The details on how to do that are documented on the OneDrive's SDK for Python GitHub page with some examples to get you started.