上传写入失败(原因=WriteError('disallowed_name',None)
UploadWriteFailed(reason=WriteError('disallowed_name', None)
我正在尝试将整个文件夹上传到保管箱,但只上传了文件。我应该以编程方式创建文件夹还是可以如此简单地解决文件夹上传问题?谢谢
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)
错误:
dropbox.exceptions.ApiError: ApiError('xxf84e5axxf86', UploadError('path', UploadWriteFailed(reason=WriteError('disallowed_name', None), upload_session_id='xxxxxxxxxxx')))
这里有几点需要注意:
- 在您的示例中,您只迭代
files
,因此您不会得到 dirs
uploaded/created。
- 虽然/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。这些将在上传时自动创建。
- 根据 /2/files/upload documentation,
disallowed_name
表示:
Dropbox will not save the file or folder because of its name.
所以,您收到此错误的原因可能是您尝试上传一个被忽略的文件,例如 ".DS_STORE"
。您可以在 this help article under "Ignored files".
中找到有关这些内容的更多信息
我正在尝试将整个文件夹上传到保管箱,但只上传了文件。我应该以编程方式创建文件夹还是可以如此简单地解决文件夹上传问题?谢谢
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)
错误:
dropbox.exceptions.ApiError: ApiError('xxf84e5axxf86', UploadError('path', UploadWriteFailed(reason=WriteError('disallowed_name', None), upload_session_id='xxxxxxxxxxx')))
这里有几点需要注意:
- 在您的示例中,您只迭代
files
,因此您不会得到dirs
uploaded/created。 - 虽然/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。这些将在上传时自动创建。 - 根据 /2/files/upload documentation,
disallowed_name
表示:
Dropbox will not save the file or folder because of its name.
所以,您收到此错误的原因可能是您尝试上传一个被忽略的文件,例如 ".DS_STORE"
。您可以在 this help article under "Ignored files".