6 Replies Latest reply on Dec 8, 2016 9:41 AM by Andre Oliveira

    Trusted Ticket with Python and Perl

    Andre Oliveira

      Hi everyone,

       

      I am trying to retrieve a trusted ticket using Perl. I've done it already using this Python script and it works, its very simple:

       

      #! python3 
      import requests   
      import sys
      import urllib3
      import getpass
      
      
      # disable SSL certificate warning
      from requests.packages.urllib3.exceptions import InsecureRequestWarning
      requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
         
      # configData   
      tableauServer = 'MYSERVER'   
      tableauUsername = MYUSER     
         
      # get trusted authentication for Tableau Server     
      wgserverURL = tableauServer + 'trusted/'
      r = requests.post(wgserverURL, data={'username': tableauUsername}, verify=False)   
         
      # validate the ticket
      # status_code has the response code, text has the ticket string   
      if r.status_code == 200:   
          if r.text != '-1':   
              ticketID = r.text   
          else:   
              print("Tableau Server could not issue trusted ticket, for more information see \n ...ProgramData\Tableau\Tableau Server\data\tabsvc\logs\wgserver\production*.log and \n ...ProgramData\Tableau\Tableau Server\data\tabsvc\logs\vizqlserver\vizql*.log \nAlso check http://onlinehelp.tableau.com/current/server/en-us/trusted_auth_trouble_1return.htm")   
              sys.exit()   
      else:   
          print('Could not get trusted ticket',str(r.status_code)) 
      

       

       

      I wrote a simple script in Perl code, however it doesn't work. What is the problem? Can you help me?

       

      use HTTP::Request::Common qw(POST);
      use LWP::UserAgent;
      
      
      # bypass ssl certificate verification
      $ENV{'PERL_LWP_SSL_VERIFY_HOSTNAME'} = 0;
      
      
      # create a user agent object
      $ua = LWP::UserAgent->new;
      
      
      #set HTTP request
      my $req = POST 'MYSERVER',
                      [ 'Username' => 'MYUSER'];
      
      
      # pass request to the user agent and get a response back
      my $resp = $ua->request($req);
      
      
      # check the outcome of the response
      if ($resp->is_success) {
          my $message = $resp->decoded_content;
          print "Received reply: $message\n";
      }
      else {
          print "HTTP POST error code: ", $resp->code, "\n";
          print "HTTP POST error message: ", $resp->message, "\n";
      }
      

       

      Thanks in advance.

       

       

      Best Regards,

       

      Andre Oliveira