Skip to content

Instantly share code, notes, and snippets.

@Ray901
Created December 24, 2024 05:33
Show Gist options
  • Select an option

  • Save Ray901/b00fac6982e7bd8cb6edf10aa6c0be6b to your computer and use it in GitHub Desktop.

Select an option

Save Ray901/b00fac6982e7bd8cb6edf10aa6c0be6b to your computer and use it in GitHub Desktop.
update tableau workbook password using Python tableau API
import tableauserverclient as TSC
import re
tableau_auth = TSC.TableauAuth('BI_USER', 'XXX')
server = TSC.Server('https://bi.com')
request_options = TSC.RequestOptions(pagesize=1000)
overwrite_credentials = True
search_server_regex = 'XXX.XXX.XXX.XXX'
search_wb_name = 'workbook name'
replace_username = 'DB_USER'
replace_pw = 'XXX'
y = 0
with server.auth.sign_in(tableau_auth):
# get all projects on site
all_workbooks, pagination_item = server.workbooks.get(req_options=request_options)
#wbname = [wb.name for wb in all_workbooks]
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): # Iterate through all connections in the workbook
if re.search(search_server_regex, wb.connections[item].server_address, re.IGNORECASE):
if re.search(search_wb_name, wb.name, re.IGNORECASE):
connection = wb.connections[item]
print(wb.connections[item].server_address,'-',wb.project_name,'-',wb.id,'-',wb.name, '-', connection.connection_type,'-',connection.id,'-',connection.username)
if overwrite_credentials:
connection.embed_password = True
connection.username = replace_username
connection.password = replace_pw
server.workbooks.update_connection(wb, connection)
y = y + 1
print("Workbook Connections Changed: {}".format(y))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment