【问题标题】:Tableau Server how to bulk update data source server name?Tableau Server 如何批量更新数据源服务器名称?
【发布时间】:2020-08-27 00:44:32
【问题描述】:

我们的 Oracle 数据库已升级到新服务器,因此它具有新的服务器名称。我们在 Tableau Server 上发布的大多数工作簿都连接到这个 Oracle 数据库。用户名和密码保持不变,但服务器地址已更改。我使用了以下 Python 代码。它可以识别需要服务器地址更新的正确工作簿,但是会产生错误:'PW Update Failed with error:

404004: Resource Not Found
    Datasource '5f125136-22da-48d0-bdc7-8e5edde8d809' could not be found.

'''

import tableauserverclient as TSC
import re

tableau_auth = TSC.TableauAuth('site_admin_username', 'site_admin_password', site_id='default') # site_id not needed if there is only one


search_server_regex = 'oldserver123' # server to search
replace_server = 'newserver123'  # use if server name/address is changing- otherwise make it the same as search_server
overwrite_credentials = False    # set to false to use existing credentials
search_for_certain_users = True # set to True if you only want to update connections for certain usernames
search_username = 'username' 
replace_username = 'username'
replace_pw = 'password'

request_options = TSC.RequestOptions(pagesize=1000) # this needs to be > # of workbooks/data connections on the site

server = TSC.Server('http://tableau_server:8000') # tableau server



y = 0   # to keep track of how many are changed

try:

    
    with server.auth.sign_in(tableau_auth):
        all_workbooks, pagination_item = server.workbooks.get(req_options=request_options)
        print("Total Workbooks to Search: {}".format(len(all_workbooks)))

        for wb in all_workbooks:
            server.workbooks.populate_connections(wb)
            for item,conn in enumerate(wb.connections): #make sure to iterate through all connections in the workbook
                if wb.connections[item].connection_type != 'sqlproxy': #sqlproxy indicates published datasource
                    if re.search(search_server_regex ,wb.connections[item].server_address,re.IGNORECASE):

                        connection = wb.connections[item]

                        if search_for_certain_users and re.search(search_username, connection.username, re.IGNORECASE):

                            # print(wb.name, '-', connection.connection_type)
                            connection.server_address = replace_server
                            connection.embed_password = False

                            if overwrite_credentials:
                                connection.embed_password = True
                                connection.username = replace_username
                                connection.password = replace_pw

                            server.datasources.update_connection(wb, connection)
                            y = y + 1

                        elif not search_for_certain_users:

                            # print(wb.name, '-', connection.connection_type)
                            connection.server_address = replace_server
                            connection.embed_password = False

                            if overwrite_credentials:
                                connection.embed_password = True
                                connection.username = replace_username
                                connection.password = replace_pw

                            server.datasources.update_connection(wb, connection)
                            y = y + 1


    print("Workbook Connections Changed: {}".format(y))

except Exception as e:
    print("PW Update Failed with error: {}".format(e))
    print("Connections Updated: {}".format(y))

''' 如何修复代码?

【问题讨论】:

  • 看起来它正在尝试更新因错误而不再存在的数据源。尝试捕获要迭代的活动数据源列表。
  • 嗨,Bernardo,数据源确实存在。我尝试搜索其他数据源。它确实识别了数据源,但得到了同样的错误。

标签: python-3.x tableau-api


【解决方案1】:

您必须更新工作簿。

server.workbooks.update_connection(wb, connection)

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-18
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-12-08
    相关资源
    最近更新 更多