Discuss Dropbox Developer & API
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
Here is the code :
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
Thanks you.
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:
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.path
value you're using: You can use users_get_current_account to check which account the app is connected to.
"/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).
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 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.
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
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.
Well, nothing is happening.
I've no error but no sucess message, i will see if it transfered my files to Nakala.
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.
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:
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.path
value you're using: You can use users_get_current_account to check which account the app is connected to.
"/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).
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.
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 !
Hi there!
If you need more help you can view your support options (expected response time for a ticket is 24 hours), or contact us on X or Facebook.
For more info on available support options for your Dropbox plan, see this article.
If you found the answer to your question in this Community thread, please 'like' the post to say thanks and to let us know it was useful!