cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 
Announcements
What’s new: end-to-end encryption, Replay and Dash updates. Find out more about these updates, new features and more here.

Dropbox API Support & Feedback

Find help with the Dropbox API from other developers.

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

accessing images from dropbox using python

accessing images from dropbox using python

henrikstaaf
Explorer | Level 3

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?

1 Accepted Solution

Accepted Solutions

Здравко
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.

View solution in original post

7 Replies 7

Greg-DB
Dropbox 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.

henrikstaaf
Explorer | 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)))

 

 

Namnlös.png

 

Здравко
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).

henrikstaaf
Explorer | 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.

henrikstaaf
Explorer | Level 3

Thank you for your help! I will try to implement what you said and solve the issue

henrikstaaf
Explorer | Level 3

I would like to tell you that it worked. I just changed 

dropbox_folder_path = '/se/1bvt14'

and voila,  

Need more support?
Who's talking

Top contributors to this post

  • User avatar
    henrikstaaf Explorer | Level 3
  • User avatar
    Здравко Legendary | Level 20
What do Dropbox user levels mean?