Search code examples
pythondropbox

UploadWriteFailed(reason=WriteError('disallowed_name', None)


I'm trying to upload a whole folder to dropbox but only the files get uploaded. Should I create a folder programatically or can I solve the folder-uploading so simple? Thanks

   import os
   import dropbox

   access_token = '***********************'

   dbx = dropbox.Dropbox(access_token)

   dropbox_destination = '/live'
   local_directory = 'C:/Users/xoxo/Desktop/man'

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

       for filename in files:
           local_path = root + '/' + filename
           print("local_path", local_path)
           relative_path = os.path.relpath(local_path, local_directory)
           dropbox_path = dropbox_destination + '/' + relative_path

           # upload the file
           with open(local_path, 'rb') as f:
               dbx.files_upload(f.read(), dropbox_path)

error:

dropbox.exceptions.ApiError: ApiError('xxf84e5axxf86', UploadError('path', UploadWriteFailed(reason=WriteError('disallowed_name', None), upload_session_id='xxxxxxxxxxx')))

Solution

  • [Cross-linking for reference: https://www.dropboxforum.com/t5/API-support/UploadWriteFailed-reason-WriteError-disallowed-name-None/td-p/245765 ]

    There are a few things to note here:

    • In your sample, you're only iterating over files, so you won't get dirs uploaded/created.
    • The /2/files/upload endpoint only accepts file uploads, not folders. If you want to create folders, use /2/files/create_folder_v2. You don't need to explicitly create folders for any parent folders in the path for files you upload via /2/files/upload though. Those will be automatically created with the upload.
    • Per the /2/files/upload documentation, disallowed_name means:

    Dropbox will not save the file or folder because of its name.

    So, it's likely you're getting this error because you're trying to upload an ignored filed, e.g., ".DS_STORE". You can find more information on those in this help article under "Ignored files".