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

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

Getting content of folders using Dropbox API in Python not working anymore since last update

There has been an update in Dropbox and also in the API somewhere in the last week. I have a Python script to retrieve the content of a Dropbox folder and it is not working anymore. The call was just as simple as:

- dbx: the active connection to Dropbox (this is still working correct)

- folder_path: the directory in which to look for

- recursive: True means to the deepest level and False means only in the specified folder

 

I came along a blog post (https://dropbox.tech/developers/api-updates-to-better-support-team-spaces), which confirms that there has changed something and i think the issue has to do with the paragraph shown below:

I tried a couple of things to change in the folder_path argument, because i thought the root path has been changed since the update, but without any success so far. 

 

Can someone explain me what i have to change to being able to retrieve the content of folders again via the Dropbox API in Python?

  • Can you clarify what you mean when you say "it is not working anymore"? For instance, what error or unexpected output do you get?

     

    For reference, regardless of what feature set your team is using exactly, if you're trying to access a "team space", you'd need to get the root namespace ID from users_get_current_account, and use that as the root in with_path_root to access the team space. You can find more information in the Team Files Guide.

  • Greg-DB's avatar
    Greg-DB
    Icon for Dropbox Staff rankDropbox Staff

    Can you clarify what you mean when you say "it is not working anymore"? For instance, what error or unexpected output do you get?

     

    For reference, regardless of what feature set your team is using exactly, if you're trying to access a "team space", you'd need to get the root namespace ID from users_get_current_account, and use that as the root in with_path_root to access the team space. You can find more information in the Team Files Guide.

    • yannick11's avatar
      yannick11
      Explorer | Level 4

      I got the following error: 

      This confirmed for me that it had to do something with the root_path. You pointed me in the right direction to use 'with_path_root' and i got it working again :).

       

      For people having the same issue in the future, this is how i got it working again:

      I use this code from github. The line with 'dbx.users_get_current_account' in the end is not sufficient anymore now. So, i changed 

      dbx.users_get_current_account()

      to

      root_namespace_id = dbx.users_get_current_account().root_info.root_namespace_id
      dbx = dbx.with_path_root(dropbox.common.PathRoot('root', value = root_namespace_id))

      and it works completely fine again.

       

      Thanks @Greg-DB!