I am trying to get a list of users who can access a workbook in my tableau server.
I am using Python, and to connect to Tableau Server I have used ['tableauserverclient'](https://tableau.github.io/server-client-python/docs/) library.
Upon executing my code, I am getting error -
raise UnpopulatedPropertyError(error)
tableauserverclient.models.exceptions.UnpopulatedPropertyError: Workbook item must be populated with permissions first.
Here is the code that I executed -
import tableauserverclient as TSC
# Set your Tableau Server URL
tableau_server_url = 'my_server_URL'
username = 'my_username'
password = 'my_password'
siteName = 'my_site_name'
# Create authentication credentials
tableau_auth = TSC.TableauAuth(username, password, site_id=siteName)
# Create a server object
tableau_server = TSC.Server(tableau_server_url)
# Disable SSL certificate verification (use with caution)
tableau_server.add_http_options({'verify': False})
# Sign in to the server
def get_users_for_workbook(workbook_id):
with tableau_server.auth.sign_in(tableau_auth):
workbook_item = tableau_server.workbooks.get_by_id(workbook_id)
permissions = workbook_item.permissions
# Extract user names and roles
for permission in permissions:
user_name = permission.grantee.name
user_role = permission.grantee_capability
print(f"User: {user_name}, Role: {user_role}")
if __name__ == "__main__":
workbook_id = '*my_workbook_id*'
print(f"Users for Workbook ID {workbook_id}:")
get_users_for_workbook(workbook_id)
This is the complete error -
Users for Workbook ID : *my_workbook_id* Traceback (most recent call last): File "c:\Demo_Python\tsc_codes\list_users.py", line 44, in <module>
get_users_for_workbook(workbook_id) File "c:\Demo_Python\tsc_codes\list_users.py", line 25, in get_users_for_workbook
permissions = workbook_item.permissions
^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\Working Directory\Python312\Lib\site-packages\tableauserverclient\models\workbook_item.py", line 75, in permissions
raise UnpopulatedPropertyError(error) tableauserverclient.models.exceptions.UnpopulatedPropertyError: Workbook item must be populated with permissions first.
It says, "Workbook item must be populated with permissions first.", but when I open the server on web, workbook already has a lot of users with permissions. So why is it saying to populate with permissions first?
Can somebody explain the error as well as provide the solution for the error please?
The "UnpopulatedPropertyError" you're encountering occurs because the Tableau Server Client (TSC) Python library requires an explicit request to populate certain properties for objects like workbooks, which includes permissions. By default, when you retrieve an object like a workbook from Tableau Server using TSC, not all properties are automatically filled in to minimize data transfer and improve performance. This is why even though your workbook has permissions set in the Tableau Server, the TSC object representing the workbook doesn't automatically have its permissions populated.
To resolve this issue, you need to explicitly request the permissions to be populated for your workbook object. This is typically done through a call that fetches these details from the server.
After retrieving the workbook item with workbook_item = tableau_server.workbooks.get_by_id(workbook_id)
, you need to populate its permissions by calling the populate_permissions
method on your workbook item.
workbook_item = tableau_server.workbooks.get_by_id(workbook_id)
tableau_server.workbooks.populate_permissions(workbook_item)
permissions = workbook_item.permissions # Now this should work without raising an error