You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何修复Tableau Server Client中的UnpopulatedPropertyError?

问题:Tableau Server获取工作簿权限用户时触发UnpopulatedPropertyError

使用Python的tableauserverclient(TSC)库连接Tableau Server,尝试获取指定工作簿的有权限用户列表时,触发UnpopulatedPropertyError,报错信息为Workbook item must be populated with permissions first。网页端已确认该工作簿配置了大量用户权限,需解释错误原因并提供解决方案。

执行代码

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)

完整报错信息

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.

错误原因

  • TSC库的workbooks.get_by_id()方法默认仅返回工作簿的基础元数据(如ID、名称),不会自动拉取权限相关信息,即便网页端已配置权限。
  • 直接访问workbook_item.permissions时,该属性未被预先填充数据,因此触发UnpopulatedPropertyError。

解决方案

必须显式调用TSC的权限填充方法,先获取工作簿的权限数据,再访问permissions属性。修改后的完整代码如下:

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)
        # 显式填充工作簿的权限数据
        tableau_server.workbooks.populate_permissions(workbook_item)
        permissions = workbook_item.permissions 

        # Extract user names and roles
        for permission in permissions:
            user_name = permission.grantee.name
            # 修正:从capabilities列表中提取权限角色
            user_role = [capability.role for capability in permission.capabilities][0]
            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)

关键修改点

  1. 添加tableau_server.workbooks.populate_permissions(workbook_item):显式向Tableau Server请求该工作簿的权限数据,并填充到workbook_item对象中。
  2. 修正权限角色提取逻辑:原代码中permission.grantee_capability属性不存在,正确方式是从permission.capabilities列表中获取role属性。

内容的提问来源于stack exchange,提问作者SnowGirl

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.28 09:25:29