We are aware of the issue with the badge emails resending to everyone, we apologise for the inconvenience - learn more here.
Forum Discussion
henrikstaaf
2 years agoExplorer | Level 3
accessing images from dropbox using python
Using Python, I am trying to download pictures from my dropbox app but I run into the following error message
"Error downloading file from Dropbox: [Errno 13] Permission denied:"
Here is my code:
import dropbox
ACCESS_TOKEN = "MY SECRET TOKEN"
dropbox_folder_path = r"my_dbx_folder_path"
local_download_path = r"my_local_download_path"
def dropbox_connect():
"""Create a connection to Dropbox."""
try:
dbx = dropbox.Dropbox(ACCESS_TOKEN)
return dbx
except Exception as e:
print('Error connecting to Dropbox with access token:', str(e))
return None
def dropbox_download_file(dropbox_file_path, local_file_path):
"""Download a file from Dropbox to the local machine."""
try:
dbx = dropbox_connect()
if dbx:
with open(local_file_path, 'wb') as f:
response = dbx.files_download(path=dropbox_file_path)
print(response)
f.write(response.content)
except Exception as e:
print('Error downloading file from Dropbox: ' + str(e))
Can I get some advice on what I am doing wrong?
henrikstaaf, as seems your application is application folder application. You should take in mind that all paths are rooted in your application (its own) folder, not the account one (something you seem haven't done)! Try with a path like '/se/1bvt14' to list your folder. 😉
Hope this helps.
- Greg-DBDropbox Staff
It sounds like that's occurring on the 'open' call for your local filesystem, not a Dropbox API call itself. Make sure you're providing the right 'local_file_path' and have permission to the specified path.
By the way, files_download returns a tuple, not a single object. You can find an example here and the documentation here. Alternatively, you can use files_download_to_file as shown here.
- henrikstaafExplorer | Level 3
Hi Greg
Thank you for your reply. I have been doing some troubleshooting and I have reduced my code sequentially to understand where the problem lies: Currently, I have the following code:
ACCESS_TOKEN = "MY_SECRET_TOKEN"
# Initialize the Dropbox client
dbx = dropbox.Dropbox(ACCESS_TOKEN)
dropbox_folder_path = '/Apps/provapp_images/se/1bvt14'
folder_metadata = dbx.files_list_folder(path=dropbox_folder_path)Notice that I have double-checked the Access token and the path. I am including a screenshot of the path further below. Anyway, I encountered the following error message:
Traceback (most recent call last):
File "C:\Users\staaf\OneDrive\Skrivbord\testparser\test.py", line 10, in <module>
folder_metadata = dbx.files_list_folder(dropbox_folder_path)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
File "C:\Users\staaf\AppData\Local\Programs\Python\Python311\Lib\site-packages\dropbox\base.py", line 2145, in files_list_folder
r = self.request(
^^^^^^^^^^^^^
File "C:\Users\staaf\AppData\Local\Programs\Python\Python311\Lib\site-packages\dropbox\dropbox_client.py", line 351, in request
raise ApiError(res.request_id,
dropbox.exceptions.ApiError: ApiError('04e0554c02a240b0939a7f63ca6a00e8', ListFolderError('path', LookupError('not_found', None)))
- ЗдравкоLegendary | Level 20
Hi henrikstaaf,
One possible thing is you have a real permission error, as stated in the message. If you try to read a local file and put it on the same place as 'local_download_path',... Did you try it? Or just try to save some dumb content there (instead of real content download from Dropbox), just to check if you're able save. If you change for a test you code to something like:
... with open(local_file_path, 'wb') as f: # response = dbx.files_download(path=dropbox_file_path) response = b"Hello world!" print(response) f.write(response.content) except Exception as e: print('Error downloading file from Dropbox: ' + str(e))
what's going on 🤔... Or try to suspend the local write like:
... if dbx: # with open(local_file_path, 'wb') as f: response = dbx.files_download(path=dropbox_file_path) print(response) # f.write(response.content) except Exception as e: print('Error downloading file from Dropbox: ' + str(e))
How changes the behavior in both cases? Where stops the error? 🧐
If I have to bet, your local path is malformed or incomplete. Check down this.
Hope this gives direction.
Add: Incomplete Dropbox path seems a logical version too or incorrectly set (or skip to set) namespace (if your account is a business one).
- henrikstaafExplorer | Level 3
However, In my latest code block, I don't even involve a local path and yet it's throwing an error. I am not that good at programming yet so perhaps I am just not understanding what you want me to try out? 😔
- ЗдравкоLegendary | Level 20
henrikstaaf, as seems your application is application folder application. You should take in mind that all paths are rooted in your application (its own) folder, not the account one (something you seem haven't done)! Try with a path like '/se/1bvt14' to list your folder. 😉
Hope this helps.
About Dropbox API Support & Feedback
Find help with the Dropbox API from other developers.
5,876 PostsLatest Activity: 4 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!