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

ConnectionError: You are already signed in with a valid auth token. #60

Open
zack-nguyen opened this issue Dec 21, 2021 · 16 comments
Open

Comments

@zack-nguyen
Copy link

zack-nguyen commented Dec 21, 2021

Hi @divinorum-webb,
After upgrade tableau server to the latest version 2021.4.2, switch_site_responses seems no longer running (I tested with tableau server version 2021.1.10 it worked)

switch_site_responses.append(connection.switch_site(site['contentUrl']))
File "D:\Python\Python39\lib\site-packages\tableau_api_lib\decorators\verification.py", line 50, in wrapper
return func(self, *args, **kwargs)
File "D:\Python\Python39\lib\site-packages\tableau_api_lib\decorators\verification.py", line 189, in wrapper
return func(self, *args, **kwargs)
File "D:\Python\Python39\lib\site-packages\tableau_api_lib\tableau_server_connection.py", line 257, in switch_site
self.auth_token = response.json().get("credentials", dict()).get("token")
File "D:\Python\Python39\lib\site-packages\tableau_api_lib\tableau_server_connection.py", line 147, in auth_token
raise ConnectionError("You are already signed in with a valid auth token.")
ConnectionError: You are already signed in with a valid auth token.

I still able to run sites_df = get_sites_dataframe(connection) but can't do switch_site_responses

Thank you

@divinorum-webb
Copy link
Owner

divinorum-webb commented Dec 28, 2021

Hi @zack-nguyen, can you double check that you have the most recent version of the library installed?
You can do this by running pip install -U tableau-api-lib in your terminal/command line.
This sounds like a familiar bug for an older version of the library when the method switching sites was not properly nullifying the original auth token when alternating sites.

Another possibility is that you are attempting to switch sites without having the appropriate permissions. If that's the case, updating to the newer version also clarifies that this may be the cause of the ConnectionError.

If you don't want to risk updating any packages in your environment (quite reasonable), you can also verify by comparing you version to the latest which is V0.1.28.

Here is some sample code I just executed, where I am successfully switching sites:

from tableau_api_lib import TableauServerConnection
from tableau_api_lib.utils import querying


config = {<my connection config>}

conn = TableauServerConnection(config, env="devyx")
conn.sign_in()

sites_df = querying.get_sites_dataframe(conn)
original_site = None

for index, site in enumerate(sites_df.contentUrl):
    if index == 0:
        original_site = site
    print(f"changing to site {site}...")
    response = conn.switch_site(site)
    print("currently on site having id: ", response.json()["credentials"]["site"]["id"])

switch_back_to_original = conn.switch_site(original_site)

conn.sign_out()

And the output:

changing to site ...
currently on site having id:  c9d3ac70-ccee-4880-aff9-3f366b299cb7
changing to site SiteA...
currently on site having id:  216ad8eb-8a7a-4582-93e2-a734e88cca52
changing to site SiteB...
currently on site having id:  dd109823-4410-4502-be54-4e8880c1fda8
changing to site SiteC...
currently on site having id:  bd2b57e6-e3a4-4cc8-971a-f82962554cd5

@zack-nguyen
Copy link
Author

zack-nguyen commented Dec 31, 2021

Hey @divinorum-webb,
I tested with 2 users, both are server administrators and should have all privilege, I also updated tableau-api-lib to v0.1.28 then tested with your sample code above and got this error:

changing to site ...
Traceback (most recent call last):
  File "C:\Users\xxx\Desktop\yyy\test.py", line 26, in <module>
    response = conn.switch_site(site)
  File "D:\Python\Python39\lib\site-packages\tableau_api_lib\decorators\verification.py", line 50, in wrapper
    return func(self, *args, **kwargs)
  File "D:\Python\Python39\lib\site-packages\tableau_api_lib\decorators\verification.py", line 189, in wrapper
    return func(self, *args, **kwargs)
  File "D:\Python\Python39\lib\site-packages\tableau_api_lib\tableau_server_connection.py", line 257, in switch_site
    self.auth_token = response.json().get("credentials", dict()).get("token")
  File "D:\Python\Python39\lib\site-packages\tableau_api_lib\tableau_server_connection.py", line 147, in auth_token
    raise ConnectionError("You are already signed in with a valid auth token or have insufficient permissions.")
ConnectionError: You are already signed in with a valid auth token or have insufficient permissions.

Have this v0.1.28 tested against Tableau latest version 2021.4.2 ?

@sheriefmdb
Copy link

Hi @zack-nguyen or @divinorum-webb, was this ever resolved? I'm running into the same issue after upgrading Tableau Server from 2021.2.7 to 2021.4.7.

@divinorum-webb
Copy link
Owner

Hey @sheriefmdb I can reproduce the error described, but only when attempting to switch to the site I'm already authenticated in. In that situation, it makes sense to me that the ConnectionError indicates already being signed in with a valid auth token.

Can you confirm that you get the error when attempting to switch to another site that isn't the one you are already signed into? For example, in my config details I authenticate into a site called Devyx.

Here are some sample sites in my test server:
image

Now when I attempt to switch_site() to the one I am already logged into, I get the error:
image

However, when I attempt to switch_site() to a site I am not currently logged into, I do not get the error:
image

We can also see here that my connection's site_id matches the id for the DevyxTemp site (see earlier screenshot).

@sheriefmdb
Copy link

Thank you for the response @divinorum-webb. What's strange is that the script was running flawlessly before the upgrade. I'm using a Personal Access Token as a Server Admin for the script. The script essentially synchs our Okta groups with our Tableau groups for user provisioning. We have 2 sites, the script works fine for the default site, but gets the following error after successfully processing the first group on the non-default site:

File " D:\Scripts\tableau_automation\tableau_okta_sync.py", line 114, in
main()
File " D:\Scripts\tableau_automation\tableau_okta_sync.py", line 54, in main
conn.switch_site(content_url='Site2')
File " D:\Scripts\tableau_automation\tableau_okta_automation\clients\tableau_server_client.py", line 255, in switch_site
self.auth_token = response.json()["credentials"]["token"]
File " D:\Scripts\tableau_automation\tableau_okta_automation\clients\tableau_server_client.py", line 135, in auth_token
raise ConnectionError("You are already signed in with a valid auth token.")
ConnectionError: You are already signed in with a valid auth token.

This is the piece of code the script uses to switch sites: conn.switch_site(content_url='Site2')

Do you think conn.switch_site possibly works differently than it did before? The script was running fine from on 2021.2.7 but is having the issue after we upgraded to 2021.4.7

Thanks again for your help!

@divinorum-webb
Copy link
Owner

Hey @sheriefmdb I don't recall any specific changes that would be causing this issue, but it's clearly an issue so I'm going to look into it further. I'll follow up in this thread when I think I have a solution. Until then, perhaps wrap your existing logic with a try/except clause that excepts the ConnectionError. An ugly temporary fix, but perhaps it will hold things over until we have a proper fix in place for you.

@sheriefmdb
Copy link

Awesome, thanks so much @divinorum-webb . Really appreciate your help here. I will try the temp fix and hopefully we can come up with a proper fix!

@divinorum-webb
Copy link
Owner

@sheriefmdb can you run pip install -U tableau-api-lib and then attempt to run your code again? I've modified the logic such that calling switch_site() on the currently active site no longer raises an exception. Previously, attempting to switch from "Site A" to "Site A" would raise an exception.

@ramirejs
Copy link

hello @divinorum-webb , I am having issues when I try to sign_out(). Whenever I first sign in then run some other functions, I want then at the end to sign out, however, I am getting the following error:

"ConnectionError: You are already signed in with a valid auth token or have insufficient permissions."

Wondering if something has changed. Would really appreciate your help/guidance.

@sheriefmdb
Copy link

Hi @divinorum-webb , I ran pip install -U tableau-api-lib again and reran the code but am getting same error. What's strange is that the script will run successfully for all the groups on my default site (about 50 or so), then run successfully for the first tableau group on my second site, then fail. So it seems like it does work for for the second site, but fails after processing one group. I haven't tried the temp fix yet, but will keep posted.

@KenH128
Copy link

KenH128 commented Jun 24, 2022

Hello @divinorum-webb, I am also running into issues when trying to sign_out(). I am getting the following error: ConnectionError: You are already signed in with a valid auth token or have insufficient permissions.
Would appreciate your help/guidance on how to resolve this issue.
Thank you

@divinorum-webb
Copy link
Owner

divinorum-webb commented Jun 25, 2022

@KenH128 @ramirejs that was a silly mistake on my part, sorry. I did not run all the tests before pushing the previous changes. I reproduced the error on my end and the latest version of the library removes the ConnectionError that was being thrown while attempting to sign out.

@KenH128
Copy link

KenH128 commented Jun 26, 2022

@divinorum-webb thank you for updating the packages to fix the sign_out error, much appreciated.

@sheriefmdb
Copy link

Hi @divinorum-webb , just wanted to check in and see if there is any available fix for the error we get when we try to switch sites. As always, really appreciate your help and support.

@divinorum-webb
Copy link
Owner

divinorum-webb commented Jun 30, 2022

@sheriefmdb not sure how to proceed because I cannot reproduce this error. Can you share as much of the relevant code as possible from the sign_in() to the error without revealing any sensitive information?

In my tests everything is working as expected:
image

@sheriefmdb
Copy link

Hey @divinorum-webb, thanks for all your help here. I forgot to close the loop here, I ended up adjusting our script and it works as expected now. Thanks again and have a good one.

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

5 participants