Cannot add user to group via TSC in python

19 Views Asked by At
import tableauserverclient as TSC

SERVER = 'xxx'
SITE = 'default'
tableau_auth = TSC.TableauAuth("sss","ddd")
server = TSC.Server(SERVER, use_server_version=True, http_options={"verify": False})

# Sign in to Tableau Server
server.auth.sign_in(tableau_auth)


def get_matching_groups(server, group_names):
        all_groups, _ = server.groups.get()
        group_dict = {group.name: group.id for group in all_groups if group.name in group_names}
        missing_groups = set(group_names) - set(group_dict.keys())
        if missing_groups:
            print(f"No groups found with names: {', '.join(missing_groups)}")
        return group_dict.values()


def get_user_ids(server, user_names):
        request_options = TSC.RequestOptions(pagesize=1000)
        all_users = list(TSC.Pager(server.users, request_options))
        user_dict = {user.name: user.id for user in all_users}
        missing_users = set(user_names) - set(user_dict.keys())
        if missing_users:
            print(f"No users found with names: {', '.join(missing_users)}")
        return [user_dict[name] for name in user_names]


# Define the group names and user names
group_names = ['test', 'Temp']
user_names = ['manlika', 'yuanyuanbao']

# Get the group IDs for the specified group names
group_ids = get_matching_groups(server, group_names)

# Get the user IDs for the specified user names
user_ids = get_user_ids(server, user_names)

# Add the specified users to the specified groups
for group_id in get_matching_groups(server,group_names):
    for user_id in get_user_ids(server,user_names):
        server.groups.add_user(group_id, user_id)

I want to add users to local groups on Tableau Server using Python. I am using following code that gets the users and groups from the cloud(our server hosted on Google Cloud Platform) and matches with the group we're passing to get IDs but keep getting the error == Attribute Error 'str' object has no attribute 'id'

0

There are 0 best solutions below