Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Internal server error 500 getting the list of connections of a virtual connection #1558

Open
kakarukeys opened this issue Jan 17, 2025 · 0 comments

Comments

@kakarukeys
Copy link

Describe the bug
getting the list of connections of a virtual connection throws an internal server error 500

Versions
Details of your environment, including:

  • Tableau Online
  • Python 3.11.9
  • TSC library version 0.35
  • API version 3.24

To Reproduce

import os
import random
from itertools import islice

import tableauserverclient as TSC


SITE_ID = "xxx"
SERVER_URL = "https://prod-apsoutheast-a.online.tableau.com"


def gen_connections(endpoint, connection_username=None):
    for obj in TSC.Pager(endpoint):
        endpoint.populate_connections(obj)

        for conn in obj.connections:
            if conn.connection_type == "athena" and (connection_username is None or conn.username == connection_username):
                yield endpoint, obj, conn


def update_keys(new_iam_access_key, new_iam_secret_key, endpoint, parent_obj, connection):
    print(f"updating to {new_iam_access_key}: {parent_obj},\n {connection}")

    connection.username = new_iam_access_key
    connection.password = new_iam_secret_key

    endpoint.update_connection(parent_obj, connection)


def rotate_keys(
    server,
    old_iam_access_key,
    new_iam_access_key,
    new_iam_secret_key,
):
    for i in range(3):
        all_items = [
            item
            for endpoint in (
                server.virtual_connections,
            )
            for item in gen_connections(endpoint, connection_username=old_iam_access_key)
        ]

        if not all_items:
            break
        elif i == 2:
            raise Exception("unable to finish the rotation task after 2 tries")

        random.Random(27).shuffle(all_items)

        for endpoint, parent_obj, connection in all_items:
            update_keys(new_iam_access_key, new_iam_secret_key, endpoint, parent_obj, connection)
            yield


if __name__ == "__main__":
    TABLEAU_PAT_TOKEN_NAME = os.getenv("TABLEAU_PAT_TOKEN_NAME")
    TABLEAU_PAT_TOKEN_VALUE = os.getenv("TABLEAU_PAT_TOKEN_VALUE")

    OLD_IAM_ACCESS_KEY = os.getenv("OLD_IAM_ACCESS_KEY")
    NEW_IAM_ACCESS_KEY = os.getenv("NEW_IAM_ACCESS_KEY")
    NEW_IAM_SECRET_KEY = os.getenv("NEW_IAM_SECRET_KEY")

    try:
        NUM = int(os.getenv("NUM")) or None
    except (TypeError, ValueError):
        NUM = None

    tableau_auth = TSC.PersonalAccessTokenAuth(TABLEAU_PAT_TOKEN_NAME, TABLEAU_PAT_TOKEN_VALUE, site_id=SITE_ID)
    server = TSC.Server(SERVER_URL, use_server_version=True)

    with server.auth.sign_in(tableau_auth):
        tasks = rotate_keys(server, OLD_IAM_ACCESS_KEY, NEW_IAM_ACCESS_KEY, NEW_IAM_SECRET_KEY)
        list(islice(tasks, NUM))

Results

Traceback (most recent call last):
  File "/Users/xxx/projects/yyy/update_key_v2.py", line 78, in <module>
    list(islice(tasks, NUM))
  File "/Users/xxx/projects/yyy/update_key_v2.py", line 38, in rotate_keys
    all_items = [
                ^
  File "/Users/xxx/projects/yyy/update_key_v2.py", line 38, in <listcomp>
    all_items = [
                ^
  File "/Users/xxx/projects/yyy/update_key_v2.py", line 17, in gen_connections
    for conn in obj.connections:
  File "/Users/xxx/Library/Caches/pypoetry/virtualenvs/yyy-eWfleEIf-py3.11/lib/python3.11/site-packages/tableauserverclient/server/pager.py", line 80, in __iter__
    current_item_list, pagination_item = self._endpoint(options)
                                         ^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/xxx/Library/Caches/pypoetry/virtualenvs/yyy-eWfleEIf-py3.11/lib/python3.11/site-packages/tableauserverclient/server/endpoint/virtual_connections_endpoint.py", line 49, in _get_virtual_database_connections
    server_response = self.get_request(f"{self.baseurl}/{virtual_connection.id}/connections", req_options)
                      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/Users/xxx/Library/Caches/pypoetry/virtualenvs/yyy-eWfleEIf-py3.11/lib/python3.11/site-packages/tableauserverclient/server/endpoint/endpoint.py", line 204, in get_request
    return self._make_request(
           ^^^^^^^^^^^^^^^^^^^
  File "/Users/xxx/Library/Caches/pypoetry/virtualenvs/yyy-eWfleEIf-py3.11/lib/python3.11/site-packages/tableauserverclient/server/endpoint/endpoint.py", line 141, in _make_request
    self._check_status(server_response, url)
  File "/Users/xxx/Library/Caches/pypoetry/virtualenvs/yyy-eWfleEIf-py3.11/lib/python3.11/site-packages/tableauserverclient/server/endpoint/endpoint.py", line 159, in _check_status
    raise InternalServerError(server_response, url)
tableauserverclient.server.endpoint.exceptions.InternalServerError: 

Internal error 500 at https://prod-apsoutheast-a.online.tableau.com/api/3.24/sites/xxx/virtualConnections/yyy/connections
b'<?xml version=\'1.0\' encoding=\'UTF-8\'?><tsResponse xmlns="http://tableau.com/api" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://tableau.com/api https://help.tableau.com/samples/en-us/rest_api/ts-api_3_24.xsd"><error code="500000"><summary>Internal Server Error</summary><detail>The server encountered an error and cannot complete your request. Contact your server administrator.</detail></error></tsResponse>'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant