I have code where I'm definitely giving the site ID
tableau_auth = TSC.TableauAuth(username=os.environ['SOMEUID'], password=os.environ['SOMEPASSWORD'], site_id ='mysite')
server = TSC.Server('https://us-east-1.online.tableau.com/', use_server_version=True)
with sign_in(): #just keeps doing server.auth.sign_in(tableau_auth) until returns a good connection
project = get_project(project_path) # just gets the project based on `/a/b/c` path
# Create the datasource object with the project_id
new_datasource = TSC.DatasourceItem(project.id)
# publish data source (specified in file_path)
try:
server.datasources.publish(
new_datasource, file_name, mode="CreateNew"
# , as_job=True
)
except TSC.ServerResponseError as e:
logger.info(f"Overwriting '{file_name}' in '{project.name}'")
new_datasource = server.datasources.publish(
new_datasource, file_name, mode="Overwrite")
except Exception as e:
logger.error(f"Problem Publishing '{file_name}' in '{project.name}'", exc_info=e)
raise
But this only happens when publishing the datasource. my other calls to sign_in work just fine.
@Vince Faller
Hi, you may try with a code I have written, for login I use PAT (Personal Access Token). As you may know, MFA would be a requirement, and after that you would need to user
import tableauserverclient as TSC
from pathlib import Path
# server admin creds
HOST="https://us-east-1.online.tableau.com/"
#USER="youruser"
#PWRD="yourpassword"
TOKENNAME="tokenname"
TOKENID="xyw==:55hP"
#Use "" to default site
SITE="yoursite"
#Use "" to default project
PROJECT_NAME="World Indicators"
ASYNC = True
FILE = "Devoluciones.hyper"
DSNAME ="Devoluciones"
server = TSC.Server(HOST, use_server_version=True)
#tableau_auth = TSC.TableauAuth(USER,PWRD,site=SITE)
tableau_auth = TSC.PersonalAccessTokenAuth(TOKENNAME, TOKENID, site_id=SITE)
PATH_TO_FILE = Path(FILE)
with server.auth.sign_in(tableau_auth):
# Define publish mode - Overwrite, Append, or CreateNew
publish_mode = TSC.Server.PublishMode.Overwrite
# Get project_id from PROJECT_NAME
all_projects, pagination_item = server.projects.get()
for project in TSC.Pager(server.projects):
if project.name == PROJECT_NAME:
project_id = project.id
new_conn_creds = None
# Create the datasource object with the project_id
datasource = TSC.DatasourceItem(project_id=project_id,name=DSNAME)
print(f"Publishing {FILE} to {PROJECT_NAME}...")
# Publish datasource
if ASYNC:
# Async publishing, returns a job_item
new_job = server.datasources.publish(datasource, PATH_TO_FILE, publish_mode, connection_credentials=new_conn_creds, as_job=ASYNC)
print("Datasource published asynchronously. Job ID: {0}".format(new_job.id))
else:
# Normal publishing, returns a datasource_item
new_datasource = server.datasources.publish(datasource, PATH_TO_FILE, publish_mode,connection_credentials=new_conn_creds)
print("Datasource published. Datasource ID: {0}".format(new_datasource.id))
#Don't forget to sign out
server.auth.sign_out()
If this post resolves the question, would you be so kind to "Select as Best"?. This will help other users find the same answer/resolution and help community keep track of answered questions. Thank you.
Regards,
Diego Martinez
Tableau Visionary and Forums Ambassador
If this post resolves the question, would you be so kind to "Select as Best"?. This will help other users find the same answer/resolution and help community keep track of answered questions. Thank you.
Regards,
Diego Martinez
Tableau Visionary and Forums Ambassador