使用 Dropbox 将目录(包括所有文件和子目录)上传到 Dropbox 时出错 Python API
Error when uploading a directory to Dropbox including all files and sub-directories with Dropbox Python API
我正在尝试将目录及其所有文件上传到 Dropbox
使用 Dropbox Python API.
包括任何子目录及其文件
文件可以正常上传,它可以创建新的 Dropbox 文件夹。我想知道是否有人对此有解决方案。
错误信息:
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)
为什么会出现这个错误,我该如何解决?
检查 Dropbox’s help center 中的忽略文件部分。
然后您可以在同步时排除此类文件。我添加了 IGNORED_FILES
变量来说明此类文件,并添加了一个 is_ignored
函数来检查文件是否会在“放置”它们之前导致该错误。
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)
我正在尝试将目录及其所有文件上传到 Dropbox 使用 Dropbox Python API.
包括任何子目录及其文件文件可以正常上传,它可以创建新的 Dropbox 文件夹。我想知道是否有人对此有解决方案。
错误信息:
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)
为什么会出现这个错误,我该如何解决?
检查 Dropbox’s help center 中的忽略文件部分。
然后您可以在同步时排除此类文件。我添加了 IGNORED_FILES
变量来说明此类文件,并添加了一个 is_ignored
函数来检查文件是否会在“放置”它们之前导致该错误。
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)