You might see that the Dropbox Community team have been busy working on some major updates to the Community itself! So, here is some info on what’s changed, what’s staying the same and what you can expect from the Dropbox Community overall.
Forum Discussion
crunchmasterdeluxe
7 months agoNew member | Level 2
Python SDK dbx.files_download error
I've been using the Python dropbox library since 2018 with no problem. I think an update was made about 3 weeks ago that stopped all my connections from working properly. To troubleshoot, I ran `pip install --upgrade dropbox` just in case.
Here is my code:
import dropbox
dbx=dropbox.Dropbox("<TOKEN>")
def download(folder, subfolder=None, name=None, sheet_name=None):
"""
Downloads a file from Dropbox and returns its contents as a DataFrame.
This function downloads a file from a specified location in Dropbox and returns
its contents as a DataFrame. You can specify the folder, subfolder, and name of
the file to be downloaded. If the file is in a binary format (e.g., Excel), you
can specify the sheet name for Excel files.
Args
-----
- folder (str): The name of the Dropbox folder where the file is located.
- subfolder (str, optional): The name of the subfolder (within the main folder)
where the file is located. Use None if the file is in the main folder.
Default is None.
- name (str, optional): The name of the file to be downloaded. Default is None.
- sheet_name (str, optional): For Excel files only, the name of the sheet to be
read. Use None for non-Excel files. Default is None.
Returns
-----
- df (pandas.DataFrame or None): A DataFrame containing the contents of the downloaded
file if the download is successful. Returns None if an error occurs during the
download.
Raises
-----
- Exception: If there is an error during the download process.
"""
try:
if subfolder != None:
path = '/%s/%s/%s' % (folder, subfolder,
name.replace(os.path.sep, '/'))
else:
path = '/%s/%s' % (folder,
name.replace(os.path.sep, '/'))
_, res = dbx.files_download(path)
with BytesIO(res.content) as stream:
if sheet_name:
df = pd.read_excel(stream, sheet_name=sheet_name)
else:
df = pd.read_csv(stream)
return df
except Exception as ex:
print('Error downloading file from Dropbox: ' + str(ex))
df = download(folder="folder_name", subfolder="subfolder_name", name="file_name")
print(df)
I have confirmed that the path is correct over and over, as well as tried subtle variations of the path construction, but every time I still get the error
ApiError('aeb48ca960a248dca978bcf4ce22782a', DownloadError('path', LookupError('not_found', None)))
Has anyone encountered this? What is the solution? I've tried downloading other files in other folders as well and I also tried creating a new app with the necessary permissions, but no luck. Thanks!
- ЗдравкоLegendary | Level 20
crunchmasterdeluxe wrote:...
I have confirmed that the path is correct over and over, as well as tried subtle variations of the path construction, but every time I still get the error
...
You have confirmed?! 🧐 How exactly? This is important!
Did you try navigate from your root to the target file? 👈👍 Just so, for check...
Fist do list with an empty path - list of the root actually. Next do list with the folder name you expected exactly as shown up in the previous call and so forth till to the file name. All the time don't type path yourself, but copy/paste from the previous call result. At the end try download with the path, passed to download method, exactly as shown in the last list call result (don't modify or use your path construction). Does the file download in this way successfully? 😉
Dump the path constructed in your method, compare with the working one, and figure your mistake out.
Good luck.
- Greg-DBDropbox Staff
crunchmasterdeluxe 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 thepath
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.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 /2/files/list_folder and /2/files/list_folder/continue to list the contents of a folder so you can check what the correctpath
values would be for items in those folder(s). To list the root, setpath
to the empty string""
when calling /2/files/list_folder. You can use thepath_lower
orid
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 /2/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 thepath
value as"/folder/example.csv"
.
- 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.
- Make sure you're using a currently accurate
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
5,882 PostsLatest Activity: 2 hours agoIf you need more help you can view your support options (expected response time for an email or 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!