Need to see if your shared folder is taking up space on your dropbox 👨💻? Find out how to check here.
Forum Discussion
GopalN
6 years agoExplorer | Level 4
Not able to get team folders or files using python sdk
Python SDK, Not Able to get files and folders where I'm using dropbox business API access token
output = dbx.DropboxTeam(_dropbox_token).as_admin(ng_member_id).files_list_folder("").entries ...
- 6 years ago
What is the value of your '_team_name_space_id' variable?
Based on the error output you shared, if you want to list the contents of the team space, you should set your '_team_name_space_id' variable to "5632093280".
Greg-DB
Dropbox Community Moderator
6 years ago[Cross-linking for reference: https://stackoverflow.com/questions/59877833/download-files-from-dropbox-team-folder-using-python-sdk/59884229?noredirect=1#comment105910967_59884229 ]
There are two things to note here that may be preventing you from listing everything you're expecting:
- The files_list_folder method isn't guaranteed to return everything in the requested folder. You need to always check the returned ListFolderResult.has_more value and if it's True, call back to files_list_folder_continue to get more results, as documented in the files_list_folder documentation.
- Dropbox API calls operate in the team member folder by default. If you're on a team with the team space configuration, that won't include your team space folders. You can access the team space though, using the 'Dropbox-API-Path-Root' header, as covered in the Namespace Guide. To set that in the Python SDK, you should use the with_path_root method. Your 'files_list_folder' code would then look something like:
output = dbx.DropboxTeam(_dropbox_token).with_path_root(dbx.common.PathRoot.root(team_space_namespace_id)).as_admin(ng_member_id).files_list_folder("").entries
print(output)
- GopalN6 years agoExplorer | Level 4
Thanks for the solution,
I have tried the above codedbx = dropbox.DropboxTeam(_dropbox_token).as_user(ng_member_id) output = dbx.with_path_root(dropbox.common.PathRoot.root(_team_name_space_id)).files_list_folder("").entries print(output)Its giving me the error :
('8928caa6ce35a895296b45e5d694ddfe', 'Error in call to API function "files/list_folder": This API function operates on a single Dropbox account
t, but the OAuth 2 access token you provided is for an entire Dropbox Business team. Since your API app key has team member file access permissions, you can operate on a team member\'s Dropbox by providing the "Dropbox-API-Select-User" HTTP header or "select_user"Note: I'm the admin and have Permission Type: Team Member file access in business API
Thanks for your solution.
- Greg-DB6 years ago
Dropbox Community Moderator
It looks like there's currently an issue with the Python SDK if you use 'as_user' or 'as_admin' before 'with_path_root'. I'll ask the team to fix that up.
As a workaround, please use 'with_path_root' before 'as_user' or 'as_admin', as in the example in my previous comment.
- GopalN6 years agoExplorer | Level 4
When I try to do with your reference code this exist with error
dropbox.exceptions.PathRootError: PathRootError('8255e7bee11bfaa054cc966323944b00', PathRootError('invalid_root', TeamRootInfo(root_namespace_id='5632093280', home_namespace_id='6821388560'
, home_path='/Gopal N')))
please suggest the solution.
- phermans6 years agoExplorer | Level 3
In your code sample, you use the variable
team_space_namespace_id
but I don't know what that is.....where do I get the id of the Team Folder? Is there a complete example of simply listing all the folders and files in a team folder using python?
Thanks
- Greg-DB5 years ago
Dropbox Community Moderator
phermans The 'team_space_namespace_id' for a team using the team space configuration would be the 'root_namespace_id' value, e.g., as returned by /2/users/get_current_account. I recommend reviewing the Team Files Guide for more context if you haven't already.
In the Python SDK in particular, you can call that via users_get_current_account, so you can get that information from the returned FullAccount.root_info.
Hopefully that should fill in the missing piece for you so you can connect that with the rest of the code and information in the earlier comments in this thread, but let us know if something still isn't working for you.
- phermans5 years agoExplorer | Level 3
Greg-DB Thanks for the quick reply. I know you are trying to be helpful but I have tried reading most of the guides, and find them to be mostly not helpful.
So I jsut tried what you suggested, and what I could glean from the Python SDK...and it still won't work.
dbxt = dropbox.DropboxTeam(_dropbox_token).as_admin(_member_id)
full_accnt = dbxt.users_get_current_account()yields an error that tells me little.....Error in call to API function "users/get_current_account": Invalid select user id format')
I don't know what a "select user id format" is, or where it is documented but it must make sense to someone who wrote this stuff.
So I looked at python sdk docs and find that it tells me this:
users_get_current_account() Get information about the current user’s account.
Wonderful.....imagine that, a function called get users_get_current_account gets the current user's account! It apparently takes no arguments and it apparently doesn't work for some esoteric reason.
Sorry for the rant, but this has already cost hours of time to attempt to do the most basic thing - get a list of files and folders in the team folder.
I will continue to guess and check until my token expires (yet again) and I waste a few more hours but after that I will probably say the hell with Dropbox API, it doesn't appear to be worth the time to learn it.
- mukesh1114 years agoNew member | Level 2output = dropbox.DropboxTeam(TOKEN).with_path_root(dropbox.common.PathRoot.root(team_space_namespace_id)).as_admin(member_id).files_list_folder("").entries
what is the team_space_namespace_id here? I use a 10-digit number
Traceback (most recent call last):
File "/home/mukesh/Documents/automation/app_test/dropbox/test_dropbox.py", line 20, in <module>
output = dropbox.DropboxTeam(TOKEN).with_path_root(dropbox.common.PathRoot.root(team_space_namespace_id)).as_admin(member_id).files_list_folder("").entries
File "/home/mukesh/Documents/BOVIWALK/projects/pose_estimation/boviwalk-ai/venv/lib/python3.10/site-packages/dropbox/base.py", line 2145, in files_list_folder
r = self.request(
File "/home/mukesh/Documents/BOVIWALK/projects/pose_estimation/boviwalk-ai/venv/lib/python3.10/site-packages/dropbox/dropbox_client.py", line 326, in request
res = self.request_json_string_with_retry(host,
File "/home/mukesh/Documents/BOVIWALK/projects/pose_estimation/boviwalk-ai/venv/lib/python3.10/site-packages/dropbox/dropbox_client.py", line 476, in request_json_string_with_retry
return self.request_json_string(host,
File "/home/mukesh/Documents/BOVIWALK/projects/pose_estimation/boviwalk-ai/venv/lib/python3.10/site-packages/dropbox/dropbox_client.py", line 596, in request_json_string
self.raise_dropbox_error_for_resp(r)
File "/home/mukesh/Documents/BOVIWALK/projects/pose_estimation/boviwalk-ai/venv/lib/python3.10/site-packages/dropbox/dropbox_client.py", line 643, in raise_dropbox_error_for_resp
raise PathRootError(request_id, err)
dropbox.exceptions.PathRootError: PathRootError('b0bc4fd1e82647deae8616b37255c2cc', PathRootError('invalid_root', TeamRootInfo(home_namespace- Здравко4 years agoLegendary | Level 20
Hi mukesh111,
Take a look on Greg's post on this page top. There is pretty clear where 'team_space_namespace_id' comes from. Try reproduce something similar. 😉 One more thing, at present access token is 'short lived' only. If you need long term access, refresh token may be object of consideration from your side.
Hope this helps.
- mukesh1114 years agoNew member | Level 2
Thanks for the reference it helped. I see that there are solutions to download files are recreate the whole structure and downloading them. Is there a single function that can handle downloading a complete directory
ex: I want to download a whole FolderA with (subfolder1, subfolder2, subfolder3)
I could only find the below for files is there for folders by any chance?:
dbx_admin_team_root.files_download_to_file()
About Discuss Dropbox Developer & API
Make connections with other developers
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!