Your workflow is unique 👨‍💻 -  tell us how you use Dropbox here.

Forum Discussion

Mgymnasts's avatar
Mgymnasts
Explorer | Level 4
2 years ago

dbx.users_get_current_account() works but dbx.files_list_folder('').entries returns Error

I am able to use OAuth and can confirm access to my dropbox account using the dropbox API. But when I run dbx.files_list_folders('').entries. I am getting dropbox eceptions.ApiError: ApiError('stringofstuff', ListFolderError('path', LookupError('not_found', None))). I am simply trying to see what my code can see so that I can then write the path I want. 

 

Is there an issue with my dropbox api settings? What else might I need to try?

5 Replies

  • Здравко's avatar
    Здравко
    Legendary | Level 20
    2 years ago

    Hi Mgymnasts,

    As seems, your API settings are fine (if there was some issue, settings related, you wont be able get to such error). It's strange such an error to appear for empty path (such path is always correct and existent). 🤔 Are you sure you had empty path set when you received that error? 🧐... Or maybe the error comes from another part of your code - try debug/look for errors in deeper.

     

    Add: Post some sample code snippet showing/reproducing your issue.

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Community Moderator rankDropbox Community Moderator
    2 years ago

    Mgymnasts As Здравко said, a path/not_found error is not expected when calling files_list_folder with a path value of the empty string ''. Like they recommended please double check the path parameter value you're setting when making that call, and double check if that's the particular call that is resulting in that error.

     

    If so, please share the actual code to reproduce the issue. In particular, I notice that you posted about calling "files_list_folders", but that isn't a method in the Dropbox Python SDK. You presumably meant "files_list_folder" (without the "s"). If you need help with this issue, please make sure to post the actual code you're using.

  • Mgymnasts's avatar
    Mgymnasts
    Explorer | Level 4
    2 years ago
    I appreciate the suggestions!  I went in and redid the OAuth to get a new stored_token and now when I run this I am not getting an error, but I also can't see the list of folders/files in the account. When my code gets to
    for entry in dbx.files_list_folder('').entries:
    print(entry.name)
     
    It is stepping right over the print as if dbx.files_list_folder(").entries isn't even there.
     
     
    Here is the code I am running (function being called that isn't returning what I expect) 
     
    def list_files_in_folder(folder_path,dbx😞
    """
    Creates a list of the files found in the folder on Dropbox.
    Parameters:
    folder_path (string): The path to the folder
    dbx: enables dropbox access
    Returns:
    files (list): List of Files in the folder
    """
    try:
    result = dbx.files_list_folder(folder_path)
    files = [entry.name for entry in result.entries if isinstance(entry, dropbox.files.FileMetadata)]
    return files
    except dropbox.exceptions.ApiError as e:
    print(f'Error listing folder contents: {e}')
    return []
    *************************IN MAIN************************
    try
    :
    dbx = dropbox.Dropbox(oauth2_refresh_token=refresh_token, app_key=d_app_key, app_secret=d_app_secret)
    # Get information about the current user's account
    account_info = dbx.users_get_current_account()

    # # Access various properties of the user's account
    account_id = account_info.account_id
    display_name = account_info.name.display_name
    email = account_info.email
    is_verified = account_info.email_verified

    # Print the user's account information
    print(f"Account ID: {account_id}")
    print(f"Display Name: {display_name}")
    print(f"Email: {email}")

    for entry in dbx.files_list_folder('').entries:
    print(entry.name)

    # Specify the Dropbox folder path you want to check or create
    dropbox_folder_path = '/SaveRx/DataForSaveRx/'
    processed_path = f'{dropbox_folder_path}/Processed/' #Not using currently

    # Enable SSL certificate validation for requests to Dropbox
    dbx._session.verify = True

    # Get the list of files in the folder
    current_files = list_files_in_folder(dropbox_folder_path, dbx)
    print(current_files)
    for file in current_files:
    print(file)
  • Здравко's avatar
    Здравко
    Legendary | Level 20
    2 years ago

    Mgymnasts wrote:
    ..., but I also can't see the list of folders/files in the account. When my code gets to
    for entry in dbx.files_list_folder('').entries:
    print(entry.name)
     
    It is stepping right over the print as if dbx.files_list_folder(").entries isn't even there.
    ...

    Mgymnasts, Is there any chance your application is App folder application (i.e. no full access and only list app's own folder only)? If so, put something in your application folder and let's see if something changes. You can also print out entries count. 😉

    Good luck.

  • Mgymnasts's avatar
    Mgymnasts
    Explorer | Level 4
    2 years ago

    Yes!  Thanks! It was right in front of my face...  

    I really appreciate the advice! Thank you!

About Discuss Dropbox Developer and API

Node avatar for Discuss Dropbox Developer and API
Explore Dropbox Developer & API discussions with developers like you.

The Dropbox Community team is active from Monday to Friday. We try to respond to you as soon as we can, usually within 2 hours.

If 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, Facebook or Instagram.

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!