2 Replies Latest reply on Jun 14, 2018 7:40 AM by Kurt Slater

    Python TSC error when trying to create new user

    Kurt Slater

      I'm fairly new to the Python TSC and having an issue trying to create new users through the API.  I can successfully connect as admin, get the list of projects, create new projects, and get the lists of users.  When I try to create a new users, I get the following error when calling server.users.add().

      tableauserverclient.server.exceptions.NotSignedInError: Missing site ID. You must sign in first.

       

      The error message is a bit confusing because I'm obviously signed in already.

       

      The key bits of my code are...

       

      # connect

      tableau_auth = TSC.TableauAuth(userID, pwd, site_id='')

      server = TSC.Server(URL)

       

      # create new user

              newU = TSC.UserItem('Test', 'Interactor')

              newU = server.users.add(newU)

              print(newU.name, newU.site_role)

       

      Any ideas or examples of using the Python library to create new users would be appreciated.

       

      On a related note, when new users are created this way, how does the initial password get set?

       

      Thanks,

      -Kurt

        • 1. Re: Python TSC error when trying to create new user
          leland.weathers

          I don't see your sign-in code:

           

          Try something like:

          # create credential objects

          tableau_auth = TSC.TableauAuth(userID, pwd, site_id='')

          server = TSC.Server(URL)

           

          # sign in

          server.auth.sign_in(tableau_auth)

           

          # create new user

          newU = TSC.UserItem('Test', 'Interactor')

          newU = server.users.add(newU)

          print(newU.name, newU.site_role)

           

          #sign out

          server.auth.sign_out()

           

           

          or use with to let the code handle the sign out for you:

          # create credential objects

          tableau_auth = TSC.TableauAuth(userID, pwd, site_id='')

          server = TSC.Server(URL)

           

          # sign in

          with server.auth.sign_in(tableau_auth):

               # create new user

               newU = TSC.UserItem('Test', 'Interactor')

               newU = server.users.add(newU)

               print(newU.name, newU.site_role)

           

           

          Example may also be seen in the documentation on github.io: Get Started

          • 2. Re: Python TSC error when trying to create new user
            Kurt Slater

            Thanks Leland.  I had been using the "with server.auth.sign_in" approach and didn't quite grasp that outside the "with" the connection would be closed.    I'm now using specific sign_in and sign_out calls which works better for what I'm trying to do.