2

I’m trying to upload a directory to Dropbox along with all its files including any sub-directories and its files using the Dropbox Python API.

Files can be uploaded alright and it can create new Dropbox folders. I wonder if anyone has a solution for this.

Error message:

Traceback (most recent call last):
File "dir_2_dropbox.py", line 27, in
client.put_file(dropbox_path, f)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/dropbox-2.2.0-py2.7.egg/dropbox/client.py", line 377, in put_file
return self.rest_client.PUT(url, file_obj, headers)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/dropbox-2.2.0-py2.7.egg/dropbox/rest.py", line 321, in PUT
return cls.IMPL.PUT(*n, **kw)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/dropbox-2.2.0-py2.7.egg/dropbox/rest.py", line 258, in PUT
return self.request("PUT", url, body=body, headers=headers, raw_response=raw_response)
File "/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/site-packages/dropbox-2.2.0-py2.7.egg/dropbox/rest.py", line 227, in request
raise ErrorResponse(r, r.read())
dropbox.rest.ErrorResponse: [400] u'The file /mobistudios/.DS_Store is on the ignored file list, so it was not saved.'

local_dir = ('/users/ninekay/desktop/scripts')

for root, dirs, files in os.walk(local_dir):

    for filename in files:

        local_path = os.path.join(root, filename)

        relative_path = os.path.relpath(local_path, local_dir)
        dropbox_path = os.path.join(‘/mobistudios’, relative_path)

        with open(local_path, 'rb') as f:
            client.put_file(dropbox_path, f)

Why do I have this error and how can I solve it?

5
  • Your error message is incomplete.
    – Berserker
    Commented Aug 16, 2015 at 11:59
  • Thanks, have updated with full error message.
    – Ninekay
    Commented Aug 16, 2015 at 12:05
  • You are trying to upload a .DS_Store file, which dropbox doesn't allow. Exclude that from your list of files to upload.
    – Berserker
    Commented Aug 16, 2015 at 12:29
  • [Cross-linking for reference: dropboxforum.com/hc/en-us/community/posts/… ]
    – Greg
    Commented Aug 16, 2015 at 17:10
  • That was it. Working fine now without those incompatible files. Thanks to every one.
    – Ninekay
    Commented Aug 17, 2015 at 4:40

1 Answer 1

2

Check the Ignored files section from Dropbox’s help center.

You could then exclude such files when sync’ing. I add the IGNORED_FILES variable to account for such files and a is_ignored function to check whether files will cause that error before ‘putting’ them.

IGNORED_FILES = ['desktop.ini', 'thumbs.db', '.ds_store',
                         'icon\r', '.dropbox', '.dropbox.attr']
def is_ignored(filename):
    filename_lower = filename.lower()
    for ignored_file in IGNORED_FILES:
        if ignored_file in filename_lower:
            return True
    return False


local_dir = ('/users/ninekay/desktop/scripts')

for root, dirs, files in os.walk(local_dir):

for filename in files:
    if is_ignored(filename):
        continue

    local_path = os.path.join(root, filename)
    relative_path = os.path.relpath(local_path, local_dir)
    dropbox_path = os.path.join(‘/mobistudios’, relative_path)


    with open(local_path, 'rb') as f:
        client.put_file(dropbox_path, f)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.