Eric J Ma's Website

How to programmatically download a file from Dropbox using Requests

written by Eric J. Ma on 2023-04-11 | tags: python dropbox file download programming requests library data storage jupyter notebooks portability internet connection content delivery personal cdn data files tutorials linux wget

Today I learned how to programmatically download a file from a Dropbox public folder. Storing it here so I remember how to do it in the future.

# Download the blog index from Dropbox using Requests.
# Taken from:
import requests
headers = {'user-agent': 'Wget/1.16 (linux-gnu)'}  # <-- the key is here!
r = requests.get("", stream=True, headers=headers)
with open("/tmp/blog_index.json", 'wb') as f:
    for chunk in r.iter_content(chunk_size=1024):
        if chunk:

I find it's useful to use Dropbox to host large data files for my Python-based tutorials, allowing me to ensure that my Jupyter notebooks are portable from computer to computer, as long as they can maintain an internet connection.

This is neat because it allows me to use Dropbox, for which I pay for storage, effectively as a personal CDN (content delivery network) with easily referenced URLs.

Cite this blog post:
    author = {Eric J. Ma},
    title = {How to programmatically download a file from Dropbox using Requests},
    year = {2023},
    month = {04},
    day = {11},
    howpublished = {\url{}},
    journal = {Eric J. Ma's Blog},
    url = {},

I send out a newsletter with tips and tools for data scientists. Come check it out at Substack.

If you would like to sponsor the coffee that goes into making my posts, please consider GitHub Sponsors!

Finally, I do free 30-minute GenAI strategy calls for teams that are looking to leverage GenAI for maximum impact. Consider booking a call on Calendly if you're interested!