To sign in and out of Tableau Server, call the Auth.sign_in and Auth.sign_out functions like so:
import tableauserverclient as TSC
tableau_auth = TSC.TableauAuth('USERNAME', 'PASSWORD')
server = TSC.Server('http://SERVER_URL')
server.auth.sign_in(tableau_auth)
# Do awesome things here!
server.auth.sign_out()
Alternatively, for short programs, consider using a with block:
import tableauserverclient as TSC
tableau_auth = TSC.TableauAuth('USERNAME', 'PASSWORD')
server = TSC.Server('http://SERVER_URL')
with server.auth.sign_in(tableau_auth):
# Do awesome things here!
# No need to call auth.sign_out() as the Auth context manager will handle that on exiting the with block
Certain environments may throw errors related to SSL configuration, such as self-signed certificates or expired certificates. These errors can be avoided by disabling certificate verification with add_http_options:
import tableauserverclient as TSC
tableau_auth = TSC.TableauAuth('USERNAME', 'PASSWORD')
server = TSC.Server('http://SERVER_URL')
server.add_http_options({'verify': False})
However, each subsequent REST API call will print an InsecureRequestWarning:
InsecureRequestWarning: Unverified HTTPS request is being made. Adding certificate verification is strongly advised. See: https://urllib3.readthedocs.io/en/latest/security.html
InsecureRequestWarning)
These warnings can be disabled by adding the following lines to your script:
import requests
from requests.packages.urllib3.exceptions import InsecureRequestWarning
requests.packages.urllib3.disable_warnings(InsecureRequestWarning)
Instead of disabling warnings and certificate verification to workaround issues with untrusted certificates, the best practice is to use a certificate signed by a Certificate Authority.
If you have the ability to do so, we recommend the following Certificate Authorities: