XD blog

blog page

dropbox, python


2015-01-20 Download a file from Dropbox with Python

It is tempting to do everything from a IPython notebook such as downloading a file from DropBox. On the web interface, when a user click on a file, a button Download shows up. A second click on this button and the file will be downloaded it. To retrieve the file from a notebook, the url of the page which contains the button but it is close from the good one. This leads to the following example:

url = "https://www.dropbox.com/[something]/[filename]?dl=1"  # dl=1 is important
import urllib.request
u = urllib.request.urlopen(url)
data = u.read()
u.close()

with open([filename], "wb") as f :
    f.write(data)

It first downloads the data as bytes and then stores everything into a file.


<-- -->

Xavier Dupré