tableau / server-client-python

A Python library for the Tableau Server REST API
https://tableau.github.io/server-client-python/
MIT License
656 stars 420 forks source link

Fix unhelpful error message when connecting to server fails: 'Invalid Version: Unknown' #1450

Open genehynson opened 2 weeks ago

genehynson commented 2 weeks ago

Describe the bug

When initializing the Tableau Server client it's possible to encounter the error message Invalid Version: Unknown which is rather confusing and does not provide enough context to debug the real issue. This occurs whenever the Tableau server name provided does not resolve to a Tableau Server (e.g. perhaps because of an SSO wall). However, the error message incorrectly implies that there is some sort of issue during the negotiation of API versions, which is very confusing.

Our usage:

import tableauserverclient as tsc
...
self._server = tsc.Server(server_name)
self._server.add_http_options({"verify": verify_ssl})
self._server.use_server_version()
self._server.auth.sign_in(auth)

This error is raised because:

I think that the invalid response payload should raise an error with a message like "Invalid server info response received from provided Tableau server url" instead of silencing this issue.

Versions Details of your environment, including:

To Reproduce Provide a url that does not resolve to a Tableau server to the client.

import tableauserverclient as tsc
_server = tsc.Server("https://getmontecarlo.com")
_server.use_server_version()
# random jwt of no significance
_server.auth.sign_in(tsc.JWTAuth(jwt="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c"))

Results

Unhelpful error is raised: InvalidVersion: Invalid version: 'Unknown'

Traceback (most recent call last):
  File "/Users/ghynson/Desktop/tableau-test/main.py", line 4, in <module>
    _server.auth.sign_in(tsc.JWTAuth(jwt="eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJzdWIiOiIxMjM0NTY3ODkwIiwibmFtZSI6IkpvaG4gRG9lIiwiaWF0IjoxNTE2MjM5MDIyfQ.SflKxwRJSMeKKF2QT4fwpMeJf36POk6yJV_adQssw5c"))
  File "/Users/ghynson/.pyenv/versions/dc11/lib/python3.11/site-packages/tableauserverclient/server/endpoint/endpoint.py", line 253, in wrapper
    self.parent_srv.assert_at_least_version(version, self.__class__.__name__)
  File "/Users/ghynson/.pyenv/versions/dc11/lib/python3.11/site-packages/tableauserverclient/server/server.py", line 194, in assert_at_least_version
    if not self.check_at_least_version(comparison):
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ghynson/.pyenv/versions/dc11/lib/python3.11/site-packages/tableauserverclient/server/server.py", line 189, in check_at_least_version
    server_version = Version(self.version or "2.4")
                     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/ghynson/.pyenv/versions/dc11/lib/python3.11/site-packages/packaging/version.py", line 200, in __init__
    raise InvalidVersion(f"Invalid version: '{version}'")
packaging.version.InvalidVersion: Invalid version: 'Unknown'