Here are the few steps for uploading files to dropbox through Python API:
1. Open link for developers https://www.dropbox.com/developers/apps and press button "create app".
2. Type your app's name and other required information. Save changes.
3. Navigate to your app's page. Click button "Generated access token".
After this operation Dropbox will create special folder with name of your applications. So all uploadings will be made relatively to this path.
1. Install Dropbox Python SDK:
pip install dropbox
2. Write a script for file uploading:
import dropbox client = dropbox.client.DropboxClient('2PHQk5obNghsfdkghst75tbi-tysilnlsctn8n048340cneucsnugskfjghsggt4BDWC') # paste here your generated token f = open('/home/myuser/somefile.txt', 'rb') response = client.put_file('/somefile.txt', f) for k, v in response.items(): print '%s: %s' % (k, v)
The output will be:
size: 284 bytes rev: 126dd0505 thumb_exists: False bytes: 284 modified: Sun, 06 Jul 2014 09:38:10 +0000 mime_type: text/plain path: /somefile.txt is_dir: False icon: page_white_text root: app_folder client_mtime: Sun, 06 Jul 2014 09:38:10 +0000 revision: 1
That's it. You'll find your file in "app_folder". For uploading file in some extra folder inside add it before file name:
response = client.put_file('/extra_folder/somefile.txt', f)
Note! If you have urllib3 old version installed on your computer, you will have an error:
Traceback (most recent call last): .... pool = pool_cls(host, port, **self.connection_pool_kw) TypeError: __init__() got an unexpected keyword argument 'ssl_version'
To avoid this just upgarde urrlib3 to the latest version (1.8.3 in my case):
sudo pip install urllib3=='1.8.3'