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!