我在 Dropbox 中找不到我上传的文件

I can't find my uploaded files in Dropbox

我正在努力将一些国家/地区的管理数据上传到我的 Dropbox 应用程序。下面是我的代码:

# importing the required libraries
import dropbox, sys, os
import requests

# Get your app key and secret from the Dropbox developer website
app_key = 'qie********'
app_secret = 'qom**********'

dbx = dropbox.Dropbox('YYPRp-*******************_JzclLe-***************-3Js')

# verify if the account is connected
dbx.users_get_current_account()

#find all the folders present
for entry in dbx.files_list_folder('').entries:
    print(entry.name)
    

# creating a path to where all the data to be uploaded is
root_dir = "H:/WORK/Upwork/Project 7 - Python School Data Analysis/Planning and Costing Model/Updated Script/Extracted" 

print ("Attempting to upload...")


z = 1
for dir, dirs, files in os.walk(root_dir):
    # the first dir is the root dir itself so we skip it
    if z == 1:
        z = z + 1
        continue
    # uploading contents of the file path
    elif z > 15:
        # split the path to get the country, which is the very last item after split (-1)
        split_dir = dir.split('\')
        folder_name = split_dir[-1] # country name
        # creating a new folder in my Dropbox for each country
        country_name = dbx.files_create_folder('/Data/'+ folder_name)
        dropbox_folder = country_name.path_display #obtaining the name of the folder
        folder_split = dropbox_folder.split('/') # splitting the path to get root folder and created folder
        folder_created = folder_split[-1] #created/country folder
        dest_path = os.path.join('/Data/', folder_created) #joining the two to make a full path
        print(dest_path)
        # looping through the files in each of the country's folder
        for file in files:
            try:
                # getting the path for each of the file in the folder
                file_path = os.path.join(dir, file)
                print(f'Uploading to {folder_name} in Dropbox')
                f = open(file_path, 'rb')
                connect = '/' # will be used to separate the destination path and the file
                # this is where the file will be saved
                d_path = os.path.join(dest_path, connect, file)
                dbx.files_upload(f.read(), d_path, mode=dropbox.files.WriteMode.overwrite)
                print(dest_path)
                print(file_path)
                print(dir)
                print('\n')
                
            except Exception as err:
                print("Error!", file, err)
    z = z + 1

代码运行成功,没有错误。这是它在控制台中的样子:

它成功地为每个国家创建了文件夹。请注意,在我所在国家/地区的文件夹中,它有多个文件(最多 15 个)。当我访问我的保管箱应用程序时,文件夹在那里,但文件夹内没有任何内容。完全没有文件,我收到消息通知说:

This Folder is Empty

见下图:

已创建文件夹

其中一个国家,没有文件:

我已经给出了一个多小时,但没有任何变化。另请注意,我配置了写入文件和文件夹所需的所有权限。我可能做错了什么吗?我将不胜感激任何帮助。谢谢!

在 Greg 的帮助下,我找到了问题所在。 files_upload class 函数需要一个工作路径作为其参数的一部分。在应用程序中找不到提供的路径,因此我添加了以下内容以使其工作:d_path = dest_path+d_path

这是完整的工作代码:

# importing the required libraries
import dropbox, sys, os
import requests

# Get your app key and secret from the Dropbox developer website
app_key = 'qie********'
app_secret = 'qom**********'

dbx = dropbox.Dropbox('YYPRp-*******************_JzclLe-***************-3Js')

# verify if the account is connected
dbx.users_get_current_account()

#find all the folders present
for entry in dbx.files_list_folder('').entries:
    print(entry.name)
    

# creating a path to where all the data to be uploaded is
root_dir = "H:/WORK/Upwork/Project 7 - Python School Data Analysis/Planning and Costing Model/Updated Script/Extracted" 

print ("Attempting to upload...")


z = 1
for dir, dirs, files in os.walk(root_dir):
    # the first dir is the root dir itself so we skip it
    if z == 1:
        z = z + 1
        continue
    # uploading contents of the file path
    elif z > 15:
        # split the path to get the country, which is the very last item after split (-1)
        split_dir = dir.split('\')
        folder_name = split_dir[-1] # country name
        # creating a new folder in my Dropbox for each country
        country_name = dbx.files_create_folder('/Data/'+ folder_name)
        dropbox_folder = country_name.path_display #obtaining the name of the folder
        folder_split = dropbox_folder.split('/') # splitting the path to get root folder and created folder
        folder_created = folder_split[-1] #created/country folder
        dest_path = os.path.join('/Data/', folder_created) #joining the two to make a full path
        print(dest_path)
        # looping through the files in each of the country's folder
        for file in files:
            try:
                # getting the path for each of the file in the folder
                file_path = os.path.join(dir, file)
                print(f'Uploading to {folder_name} in Dropbox')
                f = open(file_path, 'rb')
                connect = '/' # will be used to separate the destination path and the file
                # this is where the file will be saved
                d_path = os.path.join(dest_path, connect, file)
                d_path = dest_path+d_path
                dbx.files_upload(f.read(), d_path, mode=dropbox.files.WriteMode.overwrite)
                print(dest_path)
                print(file_path)
                print(dir)
                print('\n')
                
            except Exception as err:
                print("Error!", file, err)
    z = z + 1