8000 Add troubleshooting guide, rewrite sign in page, general improvements · tableau/server-client-python@243fc99 · GitHub
[go: up one dir, main page]

Skip to content

Commit 243fc99

Browse files
committed
Add troubleshooting guide, rewrite sign in page, general improvements
- Add troubleshooting guide for capturing REST API traffic - Add docs for site_switch() added in #655 - Rewrite sign in/out page to be more clear - Add docs for PersonalAccessTokenAuth added in #465 - Some general edits and wordsmithing
1 parent d1c6997 commit 243fc99

File tree

9 files changed

+996
-819
lines changed

9 files changed

+996
-819
lines changed

_includes/docs_menu.html

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222
<li>
2323
<a href="{{ site.baseurl }}/docs/samples">Samples</a>
2424
</li>
25+
<li>
26+
<a href="{{ site.baseurl }}/docs/troubleshooting">Troubleshooting</a>
27+
</li>
2528
<li>
2629
<a href="{{ site.baseurl }}/docs/dev-guide">Developer Guide</a>
2730
</li>

assets/fiddler.png

286 KB
Loading

docs/api-ref.md

Lines changed: 821 additions & 779 deletions
Large diffs are not rendered by default.

docs/dev-guide.md

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ add your contributions to the **development** branch.
3232
git clone git@github.com:<user-name>/server-client-python.git
3333
```
3434

35-
1. Run the tests to make sure everything is peachy:
35+
1. Run the tests to make sure everything is passing:
3636

3737
```shell
3838
python setup.py test
@@ -95,6 +95,9 @@ Here's a quick checklist to follow when coding to ensure a good pull request
9595

9696
1. Add a sample to show users how to use the new feature.
9797

98+
1. Add documentation (most likely in api-ref.md) in a separate pull request
99+
(see more below).
100+
98101
### Add tests
99102

100103
All of our tests live under the `test/` folder in the repository. We use
@@ -153,15 +156,15 @@ go together.
153156

154157
To preview and run the documentation locally, these are the steps:
155158

156-
1. Install [Ruby](https://www.ruby-lang.org/en/downloads/) (v2.5.0 or higher)
159+
1. Install [Ruby](https://www.ruby-lang.org/en/documentation/installation/) (v2.5.0 or higher).
157160

158-
1. Install [Bundler](https://bundler.io/)
161+
1. Install [Bundler](https://bundler.io/).
159162

160-
1. Install [Jekyll](https://jekyllrb.com/docs/installation/)
163+
1. Install the project dependencies (which includes Jekyll) by running `bundle install`. (In the future you can run `bundle update` to catch any new dependencies.)
161164

162-
1. Run the Jekyll site locally with `bundle exec jekyll serve`
165+
1. Run the Jekyll site locally with `bundle exec jekyll serve`.
163166

164-
1. In your browser, connect to <http://127.0.0.1:4000/server-client-python/>
167+
1. In your browser, connect to <http://127.0.0.1:4000/server-client-python/> to preview the changes. As long as the Jekyll serve process is running, it will rebuild any new file changes automatically.
165168

166-
For more details on the steps, see the GitHub Pages topic on
169+
For more details, see the GitHub Pages topic on
167170
[testing locally](https://docs.github.com/en/github/working-with-github-pages/testing-your-github-pages-site-locally-with-jekyll).

docs/index.md

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,9 @@ This section describes how to:
1919

2020
Before you install TSC, confirm that you have the following dependencies installed:
2121

22-
* Python. You can use TSC with Python 3.5 or later.
22+
* Python. You can use TSC with Python 3.5 or later.
2323
* Git. Optional, but recommended to download the samples or install from the source code.
2424

25-
2625
## Install TSC
2726

2827
You can install TSC with pip or from the source code.
@@ -31,7 +30,7 @@ You can install TSC with pip or from the source code.
3130

3231
Run the following command to install the latest stable version of TSC:
3332

34-
```
33+
```shell
3534
pip install tableauserverclient
3635
```
3736

@@ -40,7 +39,7 @@ pip install tableauserverclient
4039
You can install from the development branch for a preview of upcoming features. Run the following command
4140
to install from the development branch:
4241

43-
```
42+
```shell
4443
pip install git+https://github.com/tableau/server-client-python.git@development
4544
```
4645

@@ -49,13 +48,15 @@ development version are subject to change at any time before the next stable rel
4948

5049
### Install on an offline machine
5150

52-
To install TSC onto a machine without internet connection, use the following steps:
51+
To install TSC onto a machine without an internet connection, use the following steps:
52+
53+
1) Ensure that Python 3.5 or higher is installed.
5354

54-
1) Download and manually install the **requests** python library (and its dependencies).
55+
2) Download and manually install the `requests` Python library (and its dependencies).
5556

56-
2) Download the [setup package](https://pypi.org/project/tableauserverclient/#files){:target="_blank"}.
57+
3) Download the [setup package](https://pypi.org/project/tableauserverclient/#files){:target="_blank"}.
5758

58-
3) Run `pip install ./downloads/tableauserverclient-x.x.tar.gz`
59+
4) Run `pip install ./tableauserverclient-x.y.tar.gz`
5960

6061
## Get the samples
6162

docs/samples.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ the arguments required by a particular sample, run the sample with the `-h` flag
2121

2222
For example, if you run the following command:
2323

24-
```
24+
```shell
2525
python samples/publish_workbook.py -h
2626
```
2727

docs/sign-in-out.md

Lines changed: 92 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -3,46 +3,117 @@ title: Sign In and Out
33
layout: docs
44
---
55

6-
To sign in and out of Tableau Server, call the server's `.auth.signin` method in a `with` block.
6+
The first step to using the TSC library is to sign in to your Tableau Server (or Tableau Online). This page explains how to sign in, sign out, and switch sites, with examples for both Tableau Server and Tableau Online.
7+
8+
* TOC
9+
{:toc}
10+
11+
## Sign In
12+
13+
Signing in can be done two different ways:
14+
15+
* Personal Access Tokens - In most cases this is the preferred method because it improves security by avoiding the need to use or store passwords directly. Access tokens also expire by default if not used after 15 consecutive days. This option is available for Tableau Server 2019.4 and newer. Refer to [Personal Access Tokens](https://help.tableau.com/current/server/en-us/security_personal_access_tokens.htm) for more details.
16+
* Username and Password - Direct sign in with account username and password.
17+
18+
Examples showing both of these cases are included below.
19+
20+
**Note:** When you sign in, the TSC library manages the authenticated session for you. However, the validity of the underlying credentials token is limited by the maximum session length set on your Tableau Server (2 hours by default).
21+
22+
### Sign in with Personal Access Token
23+
24+
To sign in to Tableau Server or Tableau Online with a personal access token, you'll need the following values:
25+
26+
Name | Description
27+
:--- | :---
28+
TOKEN_NAME | The personal access token name (from the My Account settings page)
29+
TOKEN_VALUE | The personal access token value (from the My Account settings page)
30+
**Tableau Server** |
31+
SITENAME | The Tableau Server site you are authenticating with; for example in the site URL http://MyServer/#/site/MarketingTeam/projects, the site name is MarketingTeam; in the REST API documentation this field is also referred to as contentUrl; this value can be omitted to connect with the Default site on the server
32+
SERVER_URL | The Tableau Server you are authenticating with; if your server has SSL enabled, this should be an HTTPS link
33+
**Tableau Online** |
34+
SITENAME | The Tableau Online site you are authenticating with; for example in the site URL https://10ay.online.tableau.com/#/site/umbrellacorp816664/workbooks, the site name is umbrellacorp816664; in the REST API documentation this field is also referred to as contentUrl; this value is always required when connecting to Tableau Online
35+
SERVER_URL | The Tableau Online instance you are authenticating with; in the example above the server URL would be https://10ay.online.tableau.com; this will always be an an HTTPS link
36+
37+
This example illustrates using the above values to sign in with a personal access token, do some operations, and then sign out:
38+
39+
```py
40+
import tableauserverclient as TSC
41+
42+
tableau_auth = TSC.PersonalAccessTokenAuth('TOKEN_NAME', 'TOKEN_VALUE', 'SITENAME')
43+
server = TSC.Server('https://SERVER_URL', use_server_version=True)
44+
server.auth.sign_in(tableau_auth)
45+
46+
# Do awesome things here!
47+
48+
server.auth.sign_out()
49+
```
50+
51+
### Sign in with Username and Password
52+
53+
To sign in to Tableau Server or Tableau Online with a username and password, you'll need the following values:
54+
55+
Name | Description
56+
:--- | :---
57+
USERNAME | The user name
58+
PASSWORD | The user password
59+
SITENAME | The same as described in the previous section
60+
SERVER_URL | The same as described in the previous section
61+
62+
This example illustrates using the above values to sign in with a username and password, do some operations, and then sign out:
763

864
```py
965
import tableauserverclient as TSC
1066

1167
tableau_auth = TSC.TableauAuth('USERNAME', 'PASSWORD', 'SITENAME')
12-
# or for a personal access token
13-
# tableau_auth = TSC.PersonalAccessTokenAuth('TOKEN_NAME', 'TOKEN_VALUE', 'SITENAME')
14-
server = TSC.Server('https://SERVER_URL')
68+
server = TSC.Server('https://SERVER_URL', use_server_version=True)
69+
server.auth.sign_in(tableau_auth)
1570

16-
with server.auth.sign_in(tableau_auth):
17-
# Do awesome things here!
71+
# Do awesome things here!
72+
73+
server.auth.sign_out()
1874
```
1975

20-
`SERVER_URL` is the URL of your Tableau server without subpaths. For local Tableau servers, an example would be: `https://www.MY_SERVER.com`. For Tableau Online, an example would be: `https://10ax.online.tableau.com/`.
76+
## Sign Out
2177

22-
`SITENAME` is the subpath of your full site URL (also called `contentURL` in the REST API). `MYSITE` would be the site name of `https://10ax.online.tableau.com/MYSITE`. This parameter can be omitted when signing in to the Default site of an on-premise Tableau server.
78+
Signing out cleans up the current session and invalidates the authentication token being held by the TSC library.
2379

24-
`TOKEN_NAME` and `TOKEN_VALUE` are your [Personal Access Token](https://help.tableau.com/current/server/en-us/security_personal_access_tokens.htm) values, generated in your Account Settings.
80+
As shown in the examples above, the sign out call is simply:
2581

26-
Optionally, you can override the version of Tableau API you are authorizing against by adding `server.version = '<VERSION_NUMBER>'` before the `auth.signin` call.
82+
```py
83+
server.auth.sign_out()
84+
```
2785

28-
The TSC library signs you out of Tableau Server when you exit out of the `with` block.
86+
## Simplify by using Python with block
2987

30-
<div class="alert alert-info">
31-
**Note:** When you sign in, the TSC library manages the authenticated session for you, however the validity of the underlying
32-
credentials token is limited by the maximum session length set on your Tableau Server (2 hours by default).
33-
</div>
88+
The sign in/out flow can be simplified (and handled in a more Python way) by using the built-in support for the `with` block. After the block execution completes, the sign out is called automatically.
3489

35-
An alternative to using a `with` block is to call the `Auth.sign_in` and `Auth.sign_out` functions explicitly:
90+
For example:
3691

3792
```py
3893
import tableauserverclient as TSC
3994

40-
tableau_auth = TSC.TableauAuth('USERNAME', 'PASSWORD') # with no site name, this will use the Default site
41-
server = TSC.Server('http://SERVER_URL')
95+
tableau_auth = TSC.PersonalAccessTokenAuth('TOKEN_NAME', 'TOKEN_VALUE', 'SITENAME')
96+
server = TSC.Server('https://SERVER_URL')
97+
98+
with server.auth.sign_in(tableau_auth):
99+
all_wb, pagination_item = server.workbooks.get()
100+
print("\nThere are {} workbooks on site: ".format(pagination_item.total_available))
101+
for wb in all_wb:
102+
print(wb.id, wb.name)
103+
```
42104

43-
server.auth.sign_in(tableau_auth)
105+
All of the samples provided in TSC library use this technique.
44106

45-
# Do awesome things here!
107+
## Switch Site
46108

47-
server.auth.sign_out()
109+
Tableau Server has a feature which enables switching to another site without having to authenticate again. (The user must have access permissions for the new site as well.)
110+
111+
**Note:** This method is not available on Tableau Online.
112+
113+
The following example will switch the authenticated user to the NEW_SITENAME site on the same server:
114+
115+
```py
116+
# assume we already have an authenticated server object
117+
118+
server.auth.switch_site('NEW_SITENAME')
48119
```

docs/troubleshooting.md

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
---
2+
title: Troubleshooting
3+
layout: docs
4+
---
5+
6+
This page covers some common troubleshooting tips for using the TSC library.
7+
8+
<div class="alert alert-warning">
9+
<span class="glyphicon glyphicon-warning-sign" aria-hidden="true"></span> Warning: Do not post any debug logs or REST API request/response contents anywhere on GitHub. The contents may include sensitive data or authentication secrets. Instead you can post just edited snippets of relevant content after sanitizing (removing any sensitive values).
10+
</div>
11+
12+
* TOC
13+
{:toc}
14+
15+
## Logging REST API communication with Tableau Server
16+
17+
There may be cases where it's helpful to inspect the REST API calls the TSC library is making and the responses coming back from Tableau Server. Some examples might be:
18+
19+
* The TSC library is throwing an error or the results are not coming through as expected
20+
* The TSC library or the REST backend may have a bug which needs to be tracked down
21+
22+
To enable logging, add the following to your Python script ahead of making any TSC calls:
23+
24+
```py
25+
import logging
26+
logging.basicConfig(format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
27+
filename="tsc.log", level="DEBUG")
28+
```
29+
30+
Now when your script executes, you'll see a set of debug messages in the `tsc.log` file. Each API call to the REST API will be included along with the XML responses. Depending on the problem being investigated, you can compare these requests/responses to the [REST API documentation](https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api.htm) to track down the issue.
31+
32+
## Capture REST API communication with local proxy
33+
34+
Another approach for inspecting REST API traffic is to use a local debugging proxy server like [Fiddler Everywhere](https://www.telerik.com/fiddler). Fiddler Everywhere is free for basic use and has versions for Mac, Windows and Linux.
35+
36+
These are the steps to send the API traffic through to a local proxy like Fiddler:
37+
38+
1. Install Fiddler Everywhere and create a free account if needed
39+
2. Launch the Fiddler app and click the settings (gear) icon to enable Capture HTTPS traffic. (Do not click Trust root certificate.)
40+
3. Before running your script, set the following environment variables (on Windows, use SET commands instead):
41+
```shell
42+
export HTTP_PROXY=127.0.0.1:8866
43+
export HTTPS_PROXY=127.0.0.1:8866
44+
export CURL_CA_BUNDLE=""
45+
export PYTHONWARNINGS="ignore:Unverified HTTPS request"
46+
```
47+
4. Run your script
48+
5. Check Fiddler Everywhere for the results
49+
50+
The sample screenshot below shows the results of running a simple sign in/out sequence. The Capture pane includes one row for each HTTP request. Select the request to see the details on the right side: Request and Response.
51+
52+
![Fiddler Everywhere Screenshot](../assets/fiddler.png)
53+
54+
Proxy server applications other than Fiddler can be used as well. Just adjust the HTTP_PROXY and HTTPS_PROXY environment variables to use the proper IP address and port number.

docs/versions.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ layout: docs
66
Because the TSC library is a client for the Tableau Server REST API, you need to confirm that the version of the TSC
77
library that you use is compatible with the version of the REST API used by your installation of Tableau Server.
88

9+
For reference, the [REST API and Resource Versions](https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_concepts_versions.htm) page has more details about versions.
10+
911
* TOC
1012
{:toc}
1113

@@ -21,11 +23,11 @@ server = TSC.Server('http://SERVER_URL')
2123
print(server.version)
2224
```
2325

24-
For example, the code might display version `2.3`.
26+
For example, the code might display version `2.3`.
2527

2628
## Use the REST API version supported by the server
2729

28-
There are two options for always using the the latest version of the REST API that is supported by the instance of Tableau Server you are connecting to.
30+
There are two options for always using the the latest version of the REST API that is supported by the instance of Tableau Server you are connecting to. This could be necessary in cases where you're using an API feature that is only supported in a newer REST API version.
2931

3032
The first method is to specify `use_server_version=True` as one of the arguments, for example:
3133

@@ -52,7 +54,7 @@ To use a specific version of the REST API, set the version like so:
5254
import tableauserverclient as TSC
5355

5456
server = TSC.Server('http://SERVER_URL')
55-
server.version = '2.6'
57+
server.version = '3.6'
5658

5759
```
5860

@@ -62,6 +64,7 @@ The current version of TSC only supports the following REST API and Tableau Serv
6264

6365
|REST API version|Tableau Server version|
6466
|---|---|
67+
|3.9|2020.3|
6568
|3.8|2020.2|
6669
|3.7|2020.1|
6770
|3.6|2019.4|

0 commit comments

Comments
 (0)
0