Skip to content

Commit

Permalink
update getting started samples
Browse files Browse the repository at this point in the history
Add one showing proxy use
  • Loading branch information
jacalata committed Oct 4, 2023
1 parent 7ed0a43 commit 4e40f97
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 1 deletion.
2 changes: 1 addition & 1 deletion samples/getting_started/1_hello_server.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
####
# Getting started Part One of Three
# This script demonstrates how to use the Tableau Server Client to connect to a server
# You don't need to have a site or any experience with Tableau to run it
# You don't need to have a site or any experience with Tableau to run it - just know where your server is.
#
####

Expand Down
1 change: 1 addition & 0 deletions samples/getting_started/2_hello_site.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ def main():
tableau_auth = TSC.TableauAuth(username, password, site_id=site_url_name)

# OR instead of username+password, uncomment this section to use a Personal Access Token
# by commenting out the three lines above, and uncommenting these three lines
# token_name = "your-token-name"
# token_value = "your-token-value-long-random-string"
# tableau_auth = TSC.PersonalAccessTokenAuth(token_name, token_value, site_id=site_url_name)
Expand Down
56 changes: 56 additions & 0 deletions samples/getting_started/4_proxy_connections.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
####
# Getting Started: Optional Part 4
# This script demonstrates how to connect to Tableau Cloud/Server through a proxy.
# To make it easy to run, it doesn't take any arguments - you need to edit the code with your info
####

import getpass
import tableauserverclient as TSC


def main():
# 1 - replace with your server url
server_url = "https://10ax.online.tableau.com"

# 2 - add your proxy details to the server connection info
# You can also set any of the parameters of the requests.send() call shown here: stream, cert, or timeout
# https://requests.readthedocs.io/en/latest/user/advanced/#prepared-requests
use_ssl = True
my_proxies = {
'http': 'http://10.10.1.10:3128',
'https': 'http://10.10.1.10:1080',
}
server = TSC.Server(server_url, use_server_version=True, http_options={"verify": use_ssl, "proxies": my_proxies})

print("Connected to {}".format(server.server_info.baseurl))

# 3 - replace with your site name exactly as it looks in a url
# e.g https://my-server/#/this-is-your-site-url-name/
site_url_name = "" # leave empty if there is no site name in the url (you are on the default site)

# 4
username = "your-username-here"
password = getpass.getpass("Your password:") # so you don't save it in this file
tableau_auth = TSC.TableauAuth(username, password, site_id=site_url_name)

# OR instead of username+password, use a Personal Access Token (PAT) (required by Tableau Cloud)
# by commenting out the three lines above, and uncommenting these three lines
# token_name = "your-token-name"
# token_value = "your-token-value-long-random-string"
# tableau_auth = TSC.PersonalAccessTokenAuth(token_name, token_value, site_id=site_url_name)

with server.auth.sign_in(tableau_auth):
projects, pagination = server.projects.get()
if projects:
print("{} projects".format(pagination.total_available))
for project in projects:
print(project.name)

jobs, pagination = server.jobs.get()
if jobs:
print("{} jobs".format(pagination.total_available))
print(jobs[0])


if __name__ == "__main__":
main()

0 comments on commit 4e40f97

Please sign in to comment.