Using the Dropbox Module
Version 1.2 of Pythonista includes the official <a href="http://dropbox.com">Dropbox</a> Python SDK as a built-in module. Because of the way OAuth works, using it can be a little daunting at first, so I've created a minimal example that uses the webbrowser module for logging in and the keychain module for storing the credentials.
The script then just shows some information about the logged-in account, but once you're there, downloading and uploading files is relatively easy.
If you make sure that the script's name contains no spaces, you can also import it from other scripts and use the get_client function from there, so that you don't have to duplicate all that login boilerplate code everywhere you want to use the dropbox module.
Please note that you need to create a Dropbox app in order to get this to work. Go to
to create one.
Thanks, will have a look ;-)
@wrenoud Any chance you will update your script to also support the entire folder? I can't figure out what lines to change to not download my entire Dropbox first.
I've added editor.reload_files() to the script because when it creates files in pythonista my list qas not being updated unless I've ordered again or closed and opened the app.
I'm trying to run the script dropboxlogin - after creating the Dropbox app, getting the key and secret, setting these in the script and the access type to 'dropbox' - but when I run the script I get the error
"Invalid key (.......). Check your app's configuration to make sure everything. Is correct".
In this message the key string is correct. I am sure I am missing something but help would be appreciated.
@johnbenallen Make sure that the app you've configured on the Dropbox developer page is also set to "full access" (and not app folder), that's the only thing I can think of right now.
On the App Info page it says that access type is "Full Dropbox'", so should be ok.
Another thought: when I created the app I took the option "core API". Should I have selected "sync API"? This choice is not visible in the App Info page.
No, core API is right, not sure what else could have gone wrong, if you're certain that you copied the key and secret strings correctly.
Thanks for the script, it works fine. The only annoying thing was that it syncs everything, including .git/ folders and the like.
This is my solution to exclude a folder from syncing:
- move the .git folder out of the Dropbox sync folder
- create an empty .git folder in the old location
- uncheck this empty folder in the selective sync list in the Dropbox preferences. It will be deleted locally (that's why we moved it in step 1)
- move back the folder to it's previous location. Dropbox will now ignore it.
This worked perfectly. Thanks!!!
Thank you so much!
I am encountering a problem with wrenoud's otherwise excellent DropboxSync.py GIST with the latest Pythonista and the Inbox directory.
If the Inbox directory is empty, sync works perfectly. If there are files in Inbox, while upload to dropbox works fine, when I come to sync these to a different I-device, DropboxSync.py crashes with the following error when it attempts to download the Inbox file to this second device.
The error occurs on line 61 of the script when Pythonista is trying to open up a non-existent file in Inbox for writing to. The error message is:
IOError: [Errno 1] Operation not permitted: u'Inbox/filename.py'
Sync with other sub folders works perfectly.
Do any of you have an idea for how to fix this? Does the Inbox folder have special permissions? Is there an updated version of wrenoud's script which works better with Inbox?
Thanks (I'm a python newbie and fixing this seems beyond my current powers!)
Update: After some further experimentation I am coming to the conclusion that scripts are simply not allowed write access to the Inbox folder. Is this the case?
I seem unable to give scripts write access to Inbox, but have come up with a workaround. I have now added the conditional to the download function in the script:
if not head=='Inbox':
which ignores the Inbox directory and hence does not sync it.
Once I have got GIST and GitHub up and running I'll upload this as a fork.
Edit: Here is the forked version with this work around included. DropboxSync now works in 1.4 without crashing but does not sync files in Inbox directory.
That sounds super cool. Checking out your script as soon as I can!
@sidewinder: I think your conclusion is correct. Since the Inbox folder is not generated in the same way as other folders, my guess is that it is read-only to scripts, though I may be wrong.
Thanks Coder123! It is strange, the console seems to have permissions to delete scripts in that directory, but not write to it! In any case, the fix above does work now, but it is making me cringe a little. Now I have learnt more Python, a far better way of accomplishing the error handling would be to use try and except.
A nasty bug in DropboxSync deletes files with unicode characters in their filename. :-(
I've tried the dropboxlogin.py script, il works perfectly with Python 2.7 but not under 3.5's version (even when the print function is updated to the parenthesized form).
Is there a "3.5's" script version available somewhere or is there one planed ?
@bistrot Add the
#! python2she-bang at the top of the script to tell it to use the (possibly) nom-default python 2.7 interpreter.