Skip to content

Unauthorized Access error when signing out (either explicitly or at the end of a with block) #1342

Closed

Description

@bcantoni

Starting with v0.29 I notice many of my test scripts failing with an exception. It seems like a general problem rather than specific to one endpoint. Here's an example:

import tableauserverclient as TSC

tableau_auth = TSC.PersonalAccessTokenAuth(
    "xxxxx",
    "xxxxxxxxxx",
    "",
)
server = TSC.Server("https://devplat.tableautest.com", use_server_version=True)

with server.auth.sign_in(tableau_auth):
    all_wb, pagination_item = server.workbooks.get()
    print("\nThere are {} workbooks: ".format(pagination_item.total_available))
    for wb in all_wb:
        print(wb.id, wb.name, wb.tags)

The script succeeds (printing workbooks), but ends with an exception like this:

Traceback (most recent call last):
  File "/Users/bcantoni/github/server-client-python/getdatasources.py", line 14, in <module>
    with server.auth.sign_in(tableau_auth):
  File "/Users/bcantoni/github/server-client-python/tableauserverclient/server/endpoint/auth_endpoint.py", line 27, in __exit__
    self._callback()
  File "/Users/bcantoni/github/server-client-python/tableauserverclient/server/endpoint/endpoint.py", line 291, in wrapper
    return func(self, *args, **kwargs)
  File "/Users/bcantoni/github/server-client-python/tableauserverclient/server/endpoint/auth_endpoint.py", line 85, in sign_out
    self.post_request(url, "")
  File "/Users/bcantoni/github/server-client-python/tableauserverclient/server/endpoint/endpoint.py", line 248, in post_request
    return self._make_request(
  File "/Users/bcantoni/github/server-client-python/tableauserverclient/server/endpoint/endpoint.py", line 165, in _make_request
    self._check_status(server_response, url)
  File "/Users/bcantoni/github/server-client-python/tableauserverclient/server/endpoint/endpoint.py", line 186, in _check_status
    raise NotSignedInError(server_response.content, url)
tableauserverclient.server.endpoint.exceptions.NotSignedInError: (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_22.xsd"><error code="401002"><summary>Unauthorized Access</summary><detail>Invalid authentication credentials were provided.</detail></error></tsResponse>', 'https://10ax.online.tableau.com/api/3.22/auth/signout')

If I switch from using the with statement to the older style, it works fine:

import tableauserverclient as TSC

tableau_auth = TSC.PersonalAccessTokenAuth(
    "xxxx",
    "xxxxxxx",
    "",
)
server = TSC.Server("https://devplat.tableautest.com", use_server_version=True)

server.auth.sign_in(tableau_auth)

all_wb, pagination_item = server.workbooks.get()
print("\nThere are {} workbooks: ".format(pagination_item.total_available))
for wb in all_wb:
    print(wb.id, wb.name, wb.tags)

Testing notes:

  • I tested with same results on both Tableau Cloud and Server.
  • This seems new to 0.29; switching back to 0.28 solves the issue.
  • Git bisect points to Issue 1299 #1300 as the point this was introduced
  • In server/endpoint/endpoint.py, changing seconds = 0.05 back to seconds = 0 seems to fix it (but I'll admit I don't totally follow the changes in that PR)

Activity

  1. BerndRos commented on Jan 17, 2024

    @BerndRos

    I think this is due to the server.auth.sign_out() which is automatically called at the end of the with-statement.
    When you include the logout in your older style this error should come up aswell.

  2. gordonstrodel commented on Jan 17, 2024

    @gordonstrodel

    @bcantoni - Confirmed. We are seeing the same error message initiating refreshes on Tableau Cloud on the latest copy of tableauserverclient from within our instance of Databricks (running python). Explicitly installing 0.28 seems to fix the problem. (Thank you @mfalkenham).

    NotSignedInError: (b'Unauthorized AccessInvalid authentication credentials were provided.', 'https://us-east-1.online.tableau.com/api/3.21/auth/signout')

    Is there a decision from Tableau on if this will be fixed? Or should we just update our code to remove the "with" as noted above?

  3. bcantoni commented on Jan 17, 2024

    @bcantoni
    ContributorAuthor

    @BerndRos ahh thanks for pointing that out - I confirmed in my workaround calling sign_out does cause the same exception.

  4. changed the title [-]Unauthorized Access error when using `with` statement along with auth sign-in[/-] [+]Unauthorized Access error when signing out (either explicitly or at the end of a `with` block)[/+] on Jan 17, 2024
  5. BobDu commented on Jan 18, 2024

    @BobDu

    Another fast and dirty solution

    import tableauserverclient as TSC
    
    tableau_auth = TSC.PersonalAccessTokenAuth(
        "xxxxx",
        "xxxxxxxxxx",
        "",
    )
    server = TSC.Server("https://devplat.tableautest.com", use_server_version=True)
    
    server.auth.sign_out = lambda: None  # Set sign_out() as a empty func
    
    with server.auth.sign_in(tableau_auth):
        all_wb, pagination_item = server.workbooks.get()
        print("\nThere are {} workbooks: ".format(pagination_item.total_available))
        for wb in all_wb:
            print(wb.id, wb.name, wb.tags)
  6. jacalata commented on Jan 18, 2024

    @jacalata
    Contributor

    This error is caused by the threading code repeating the signout call. I'm pretty sure that all of the four issues logged on 0.29 are caused the same way. I'm working on a fix.

  7. added a commit that references this issue on Jan 19, 2024
  8. TWeatherston commented on Jan 24, 2024

    @TWeatherston

    Don't want to add any pressure but do you have a rough idea when the fix for this might be released? We're trying to plan our server upgrade and the release will help us figure out a good plan for it 😄

  9. bcantoni commented on Jan 26, 2024

    @bcantoni
    ContributorAuthor
  10. kykrueger commented on Feb 27, 2024

    @kykrueger
    Contributor

    @bcantoni , just saw this now. I'd like to give a bit of post-mortem info about #1300 and #1299 and this issue.

    #1299 was an issue with only some versions of tableau-server, and I'd thought that the server was timing out while waiting to transfer another chunk in large hyper-files. My solution was to reduce the waiting times in order to catch the responses faster. At the beginning of the async request I'd shortened the wait from 1 s to 0.05 s. And in the loops of waiting from 10 s to 0.1 s.

    https://github.com/tableau/server-client-python/pull/1300/files#diff-8feeb8c658f1ffad9f0759325efb691f9f3069dfc2f47510df60bf4131cd0454R105-R108

    https://github.com/tableau/server-client-python/pull/1300/files#diff-272aad84961c6c3a77035102d1201422c605408f42a2f4aaa5d42d4555560f73L10-R10

    This solved the issue of failed uploads with larger hyperfiles on older versions of tableau server, where we discovered the issue was Tableau-Server 2022.1.13. We were not able to reproduce the issue on 2022.1.16, so it seemed to depend on the Server version.

    In hindsight, it looks like the async completion flag that was being used hadn't been working reliably. To find the exact cause of the issue, I'd suggest looking at the client's compatibility with multiple versions of tableau-server, as I suspect the new problem was introduced with an update of tableau-server and not with the client. Perhaps the timings for transactions were made tighter with the new version, reintroducing this issue, which makes sense for me that by further reducing the sleep time at the start of the transaction had solved the issue for you.

    The client did have an overall issue with the async completion, so the new fix of removing async completely seems like a more robust solution.

  11. added a commit that references this issue on May 5, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions