cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
Want to know what we learned at IBC? Check out our learnings on media, remote working and more right here.

Discuss Dropbox Developer & API

cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

Trying to export files from folders and subfolders to Nakala

Trying to export files from folders and subfolders to Nakala

Cryo
Explorer | Level 4
Go to solution

Hello.

 

I'm part of a project and i need to export all the Dropbox's files to Nakala which is a data warehouse.

I'm having difficulties listing the Dropbox folders, i think the script doesnt recognize them even when i have the right path to them

Cryo_0-1726566747235.png

Here is the code  : 

 

Spoiler

import dropbox
import requests

# Dropbox and Nakala authentication
DROPBOX_ACCESS_TOKEN = ''
NAKALA_API_URL = "https://apitest.nakala.fr/data/"
NAKALA_API_KEY = "01234567-89ab-cdef-0123-456789abcdef"
dbx = dropbox.Dropbox(DROPBOX_ACCESS_TOKEN)

# Step 1: Recursively list folders and files in Dropbox
def list_all_folders_and_upload_to_nakala(folder_path=""):
try:
result = dbx.files_list_folder(folder_path, recursive=True)
print("Folders and files in Dropbox:")
for entry in result.entries:
if isinstance(entry, dropbox.files.FileMetadata):
file_path_in_dropbox = entry.path_lower
print(f"Processing file: {file_path_in_dropbox}")

# Download the file from Dropbox
file_content = download_from_dropbox(file_path_in_dropbox)

# Upload to Nakala
if file_content:
print(f"Uploading {entry.name} to Nakala...")
upload_to_nakala(entry.name, file_content)
elif isinstance(entry, dropbox.files.FolderMetadata):
print(f"Folder: {entry.path_display}")
except Exception as e:
print(f"Error listing Dropbox folders: {e}")

# Step 2: Download file from Dropbox
def download_from_dropbox(file_path):
try:
metadata, res = dbx.files_download(path=file_path)
print(f"Downloaded: {file_path}")
return res.content
except Exception as e:
print(f"Error downloading from Dropbox: {e}")
return None

# Step 3: Upload file to Nakala
def upload_to_nakala(file_name, file_content):
files = {
'file': (file_name, file_content),
}
headers = {
'Authorization': f'Bearer {NAKALA_API_KEY}',
}
try:
response = requests.post(NAKALA_API_URL, headers=headers, files=files)
if response.status_code == 200:
print(f"File {file_name} uploaded successfully to Nakala!")
else:
print(f"Error uploading {file_name} to Nakala: {response.status_code}, {response.text}")
except Exception as e:
print(f"Error during Nakala upload: {e}")

# Main workflow
folder_path_in_dropbox = "/Sète"
list_all_folders_and_upload_to_nakala(folder_path_in_dropbox)

 

I would like to know why this doesnt work, when i have the folder created 

Cryo_1-1726567026778.png

Thanks you.

 

1 Accepted Solution

Accepted Solutions

Greg-DB
Dropbox Staff
Go to solution

A "path/not_found" Dropbox API error indicates that the API call failed because there was nothing currently found at the specified path in the connected account under the relevant root. For example, this can happen if there's a mistake or typo in the path value the app supplies, if the file/folder has been renamed, moved, or deleted from that path, if the app is not connected to the correct account for that particular path, etc.

 

When specifying the path, make sure you provide the full and accurate path for the desired file under the relevant root. For example, if you have a file named "example.csv" inside a folder named "folder", the path would be "/folder/example.csv". You can find more information on path formats here.

 

I see Здравко already helpfully covered some of this, but to elaborate a bit, here are several things you can check in particular to debug this:
 

  • Make sure you're using a currently accurate path value: You can use files_list_folder and files_list_folder_continue to list the contents of a folder so you can check what the correct path values would be for items in those folder(s). To list the root, set path to the empty string "" when calling files_list_folder. You can use the path_lower or id values returned for the files/folders in that folder to interact with those files/folders.
     
  • Make sure you're connected to the correct account for the path value you're using: You can use users_get_current_account to check which account the app is connected to.

 

  • Make sure you're using app folder-relative paths, if your app is registered for the "app folder" access type: Apps with the "app folder" access type can only access the contents of the special app folder that gets automatically created for it. If your app has the "app folder" access type, then it will only be able to access files in the app folder, and the root for any path value supplied by that app will automatically be the app folder root. You can find more information on app permissions here. For example, If your app has the app folder access type and you're trying to access something you can see on the Dropbox web site at "/Apps/<app folder name>/folder/example.csv", you should only send the path value as "/folder/example.csv". Alternatively, if your app is registered for the "app folder" access type but you need to access contents outside the app folder, you'll need to use a different app registration with the full Dropbox access type instead (or you can move the contents into the app folder).

 

  • Make sure you're accessing the relevant root: When using an app with the "full Dropbox" access type, API calls default to the member folder, but if you're trying to access the "team space" (only applicable to members of a team with the "team space" configuration), you'll need to configure that as the root explicitly, as covered in the Team Files Guide.

 

Given the existence of "Applications" in your screenshot though, it seems like you may have registered an app with the app folder access type, but are trying to access a folder "/Sète" outside the app folder, which would fail, so take note of the third list item above in particular.

View solution in original post

7 Replies 7

Здравко
Legendary | Level 20
Go to solution

@Cryo wrote:

...

I would like to know why this doesnt work, when i have the folder created 

...


Hi @Cryo,

Is there something in your folder you're trying to process? 🤔 What does actually your script output? (eventual error message or something like)

Something else that may confuse you is skipping the fact that folder listing is in pages (or may be at least). Using files_list_folder returns only the first page, not entire folder content! You didn't check has_more field to see if there may be next pages. Do this and call files_list_folder_continue too whenever needed for full folder content list. 😉

Hope this gives direction.

Cryo
Explorer | Level 4
Go to solution

Cryo_0-1726576887021.png

Yes there is pictures files.

 

C:\Users\Maxime\Desktop\Nouveau dossier (7)>python python3.py
Error listing Dropbox folders: ApiError('4e3209586ff04f77b802c4b0073f44b6', ListFolderError('path', LookupError('not_found', None)))

 

I have this API error, i don't know why but he cant find anything. When i tried root folder, it found nothing as well but i have a message Folders and files in Dropbox with a blank.

 

Code is like that : 

 

import dropbox
import requests

# Dropbox and Nakala authentication
DROPBOX_ACCESS_TOKEN = '.9lC4QlMUxkABZ8fN1H3-wzkKB3Wf5XiDzOKMEItluZw2FxoiKC93UX52k4vlLOmWlywyRwKvkZ'
NAKALA_API_URL = "https://apitest.nakala.fr/data/"
NAKALA_API_KEY = "01234567-89ab-cdef-0123-456789abcdef"
dbx = dropbox.Dropbox(DROPBOX_ACCESS_TOKEN)

# Step 1: Recursively list folders and files in Dropbox with pagination
def list_all_folders_and_upload_to_nakala(folder_path=""):
try:
result = dbx.files_list_folder(folder_path, recursive=True)
process_entries(result.entries)

# Check if more entries are available and continue listing
while result.has_more:
result = dbx.files_list_folder_continue(result.cursor)
process_entries(result.entries)

except Exception as e:
print(f"Error listing Dropbox folders: {e}")

# Process each entry (file or folder) found in Dropbox
def process_entries(entries):
for entry in entries:
if isinstance(entry, dropbox.files.FileMetadata):
file_path_in_dropbox = entry.path_lower
print(f"Processing file: {file_path_in_dropbox}")

# Download the file from Dropbox
file_content = download_from_dropbox(file_path_in_dropbox)

# Upload to Nakala
if file_content:
print(f"Uploading {entry.name} to Nakala...")
upload_to_nakala(entry.name, file_content)
elif isinstance(entry, dropbox.files.FolderMetadata):
print(f"Folder: {entry.path_display}")

# Step 2: Download file from Dropbox
def download_from_dropbox(file_path):
try:
metadata, res = dbx.files_download(path=file_path)
print(f"Downloaded: {file_path}")
return res.content
except Exception as e:
print(f"Error downloading from Dropbox: {e}")
return None

# Step 3: Upload file to Nakala
def upload_to_nakala(file_name, file_content):
files = {
'file': (file_name, file_content),
}
headers = {
'Authorization': f'Bearer {NAKALA_API_KEY}',
}
try:
response = requests.post(NAKALA_API_URL, headers=headers, files=files)
if response.status_code == 200:
print(f"File {file_name} uploaded successfully to Nakala!")
else:
print(f"Error uploading {file_name} to Nakala: {response.status_code}, {response.text}")
except Exception as e:
print(f"Error during Nakala upload: {e}")

# Main workflow
folder_path_in_dropbox = "/Sète"
list_all_folders_and_upload_to_nakala(folder_path_in_dropbox)

 

/spo

Здравко
Legendary | Level 20
Go to solution

As the error message shows, you don't point your folder in correct way. There are number of possibilities, but instead of I speculate, better just you start from the root - empty path instead of some concrete - it's always correct one.

Let's see what will get up.

Cryo
Explorer | Level 4
Go to solution

Well, nothing is happening.

Cryo_0-1726577995565.png

 

I've no error but no sucess message, i will see if it transfered my files to Nakala.

Здравко
Legendary | Level 20
Go to solution

Are you sure you point (access token comes from) the correct account and also is that account a team account or individual one? Keep in mind that by default API access only home folder. For individual accounts, this is the account root, but for team account with shared space it's a subfolder (member home folder) in the account root namespace! Something that may confuse you.

Check the state carefully. Use users_get_current_account to check the account.

Good luck.

Greg-DB
Dropbox Staff
Go to solution

A "path/not_found" Dropbox API error indicates that the API call failed because there was nothing currently found at the specified path in the connected account under the relevant root. For example, this can happen if there's a mistake or typo in the path value the app supplies, if the file/folder has been renamed, moved, or deleted from that path, if the app is not connected to the correct account for that particular path, etc.

 

When specifying the path, make sure you provide the full and accurate path for the desired file under the relevant root. For example, if you have a file named "example.csv" inside a folder named "folder", the path would be "/folder/example.csv". You can find more information on path formats here.

 

I see Здравко already helpfully covered some of this, but to elaborate a bit, here are several things you can check in particular to debug this:
 

  • Make sure you're using a currently accurate path value: You can use files_list_folder and files_list_folder_continue to list the contents of a folder so you can check what the correct path values would be for items in those folder(s). To list the root, set path to the empty string "" when calling files_list_folder. You can use the path_lower or id values returned for the files/folders in that folder to interact with those files/folders.
     
  • Make sure you're connected to the correct account for the path value you're using: You can use users_get_current_account to check which account the app is connected to.

 

  • Make sure you're using app folder-relative paths, if your app is registered for the "app folder" access type: Apps with the "app folder" access type can only access the contents of the special app folder that gets automatically created for it. If your app has the "app folder" access type, then it will only be able to access files in the app folder, and the root for any path value supplied by that app will automatically be the app folder root. You can find more information on app permissions here. For example, If your app has the app folder access type and you're trying to access something you can see on the Dropbox web site at "/Apps/<app folder name>/folder/example.csv", you should only send the path value as "/folder/example.csv". Alternatively, if your app is registered for the "app folder" access type but you need to access contents outside the app folder, you'll need to use a different app registration with the full Dropbox access type instead (or you can move the contents into the app folder).

 

  • Make sure you're accessing the relevant root: When using an app with the "full Dropbox" access type, API calls default to the member folder, but if you're trying to access the "team space" (only applicable to members of a team with the "team space" configuration), you'll need to configure that as the root explicitly, as covered in the Team Files Guide.

 

Given the existence of "Applications" in your screenshot though, it seems like you may have registered an app with the app folder access type, but are trying to access a folder "/Sète" outside the app folder, which would fail, so take note of the third list item above in particular.

Cryo
Explorer | Level 4
Go to solution

Thanks you very much !

 

I didn't have the folder in the application folder, i just put it here and it is working.

Have a great day !

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    Cryo Explorer | Level 4
  • User avatar
    Greg-DB Dropbox Staff
  • User avatar
    Здравко Legendary | Level 20
What do Dropbox user levels mean?