upload file to my dropbox from python script

dropbox, python, upload

Solution

Important Note: this answer is deprecated since dropbox uses v2 API now. See the answer of @SparkAndShine for current API version solution

Thanks to @smarx for the answer above! I just wanted to clarify for anyone else trying to do this.

Make sure you install the dropbox module first of course, `pip install dropbox`.

Create an app under your own dropbox account in the "App Console". (https://www.dropbox.com/developers/apps)

Just for the record I created my App with the following:

a. App Type as "Dropbox API APP".

b. Type of data access as "Files & Datastores"

c. Folder access as "My app needs access to files already on Dropbox". (ie: Permission Type as "Full Dropbox".)

Then click the "generate access token" button and cut/paste into the python example below in place of `<auth_token>`:

import dropbox

client = dropbox.client.DropboxClient(<auth_token>)
print 'linked account: ', client.account_info()

f = open('working-draft.txt', 'rb')
response = client.put_file('/magnum-opus.txt', f)
print 'uploaded: ', response

folder_metadata = client.metadata('/')
print 'metadata: ', folder_metadata

f, metadata = client.get_file_and_metadata('/magnum-opus.txt')
out = open('magnum-opus.txt', 'wb')
out.write(f.read())
out.close()
print metadata

Problem

I want to upload a file from my python script to my dropbox account automatically. I can't find anyway to do this with just a user/pass. Everything I see in the Dropbox SDK is related to an app having user interaction. I just want to do something like this: https://api-content.dropbox.com/1/files_put//?user=me&pass=blah

Original source

Related problems