Open
Description
I'm moving from using a PAT to using a JWT. The following code worked with a PAT but I can't seem to get it to work using a JWT. I've scoped everything and it says in the Tableau docs that you should be able to update connection details with a JWT. I'm getting an unauthorized error for this. I was able to do a number of other operations with the JWT, just not this one.
import tableauserverclient as TSC
import jwt
from datetime import timezone, datetime, timedelta
import uuid
jwt_token = jwt.encode(
{
"iss": client_id,
"exp": datetime.utcnow() + timedelta(minutes=10),
"jti": str(uuid.uuid4()),
"aud": "tableau",
"sub": "[email protected]",
"scp": ["tableau:*"]}, ###everything in scope
secret_key,
algorithm = "HS256",
headers = {
'kid': secret_id,
'iss': client_id
}
)
tableau_auth = TSC.JWTAuth(token, 'my_site')
server = TSC.Server('https://us-east-1.online.tableau.com/', use_server_version=True)
with server.auth.sign_in(tableau_auth):
for wb in TSC.Pager(server.workbooks):
server.workbooks.populate_connections(wb)
for connection in wb.connections: #### breaks here on wb.connections<<<<<
creds = get_correct_creds(connection)
if (creds):
connection.username = creds["user"]
connection.password = creds["password"]
server.workbooks.update_conn(wb, connection)