0 Replies Latest reply on May 21, 2020 10:04 PM by Arun Yadav

    How to update server info in connection string in multiple workbooks on server

    Arun Yadav

      Hi,

       

      I'm trying to update server name in the connection info for multiple workbooks.

      Few of my workbooks have multiple embedded data sources. My below script is able to update new server name in some of the workbooks but its failing to update server name in few workbooks where I have multiple data sources.

      Can someone help me to fix this script ?

       

      import tableauserverclient as TSC

      tableau_auth = TSC.TableauAuth('ID', 'PWD', site_id='SITE')

      server = TSC.Server('ServerURL')

      server.auth.sign_in(tableau_auth)

      book = xlrd.open_workbook('Excel Sheet containing LUIDs of workbooks')

      xl_sheet = book.sheet_by_name('Sheet1')

      for i in range(xl_sheet.nrows):

      row = xl_sheet.row_values(i)

      for cell in row:

      #with server.auth.sign_in(headers):

      print("here1 , starting with row number: " + str(i))

      print(cell)

      try: with open("Logs.txt", "a") as f1:

      workbook = server.workbooks.get_by_id(cell)

      print("below mentioned is workbook id")

      f1.write("\nworkbook id is " + workbook.id)

      print(workbook.id)

        server.workbooks.populate_connections(workbook)

      print("\nThe connections for {0}: ".format(workbook.name))

      print([connection.datasource_name for connection in workbook.connections])

      print([connection.id for connection in workbook.connections])

      connection = workbook.connections[0]

      connection.server_address='new server address'

      connection.username = 'username'

      connection.password = 'pwd'

      connection.embed_password=True

      server.workbooks.update_connection(workbook, connection) except:

      print("inside except block")

       

      Or if there is any other better solution , pls let me know.

       

      TIA !!

       

      Regards,

      Arun