4 Replies Latest reply on Dec 6, 2019 3:49 PM by kate summer

    How to run list.py in the Tableau_tools library?

    kate summer

      I am getting start with the sample scripts in Tableau_tools Samples .

       

      I can't get the list.py to run. I modified four places:server address, only have default site, username, and password.

      The error message I got is below:

      usage: ipykernel_launcher.py [-h] --server SERVER [--site SITE] --username USERNAME [--password PASSWORD] [--logging-level {debug,info,error}] {workbook,datasource,project,view,job} ipykernel_launcher.py: error: argument resource_type: invalid choice: 'C:\\Users\\xxxx\\AppData\\Roaming\\jupyter\\runtime\\kernel-0fc52a63-9ad8-4032-a0a3-adbd168664ae.json' (choose from 'workbook', 'datasource', 'project', 'view', 'job')

       

      How to fix the error?

      After downloading the sample file, am I supposed to open each script to fill in my server's information? Can I store the server address, username, password in one text file, and call that file in the script? Is there a way the encrypt the password?

       

       

       

       

      import argparse

      import getpass

      import logging

       

       

      import tableauserverclient as TSC

       

       

       

       

      def main():

          parser = argparse.ArgumentParser(description='List out the names and LUIDs for different resource types')

          parser.add_argument('--server', '-s', required=True, help='server address')

          parser.add_argument('--site', '-S', default=None, help='')

          parser.add_argument('--username', '-u', required=True, help='myname')

          parser.add_argument('--password', '-p', default=None, help='password')

       

       

          parser.add_argument('--logging-level', '-l', choices=['debug', 'info', 'error'], default='error',

                              help='desired logging level (set to error by default)')

       

       

          parser.add_argument('resource_type', choices=['workbook', 'datasource', 'project', 'view', 'job'])

       

       

          args = parser.parse_args()

       

       

          if args.password is None:

              password = getpass.getpass("Password: ")

          else:

              password = args.password

       

       

          # Set logging level based on user input, or error by default

          logging_level = getattr(logging, args.logging_level.upper())

          logging.basicConfig(level=logging_level)

       

       

          # SIGN IN

          tableau_auth = TSC.TableauAuth(args.username, password, args.site)

          server = TSC.Server(args.server, use_server_version=True)

          with server.auth.sign_in(tableau_auth):

              endpoint = {

                  'workbook': server.workbooks,

                  'datasource': server.datasources,

                  'view': server.views,

                  'job': server.jobs,

                  'project': server.projects,

              }.get(args.resource_type)

       

       

              for resource in TSC.Pager(endpoint.get):

                  print(resource.id, resource.name)

       

       

       

       

      if __name__ == '__main__':

          main()