I’m trying to upload a directory to Dropbox along with all its contents
including any sub-directories and its contents using the Python API.
I can upload files OK and even create new Dropbox folders. I wonder if
anyone has a solution for this. Any help or code examples would be greatly
appreciated. Below the error message you can see the code.
The error message is as follows.
Traceback (most recent call last):
File "dir_2_dropbox.py", line 27, in <module>
response = 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())
Python code.
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)