Skip to main content

Our API version is 3.11 and I won't be able to get our IT guys to upgrade. So crud with a hyper file isn't possible.

 

The below code is currently working fine with an exeption. The hyper_name below is prebuilt in a prior snippet, but in testing I've limited it's rows to 1000. Makes this code work fine. It publishes a hyper file, with 1000 rows in it. All pre-built using PySpark (so a dataframe in to the hyper file).

from pathlib import Path

path_to_database = Path(hyper_name)

project_name = 'Testing'

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

# Create the datasource object with the project_id

datasource = TSC.DatasourceItem(project_id)

print(f"Publishing {hyper_name} to {project_name}...")

# Publish datasource

datasource = server.datasources.publish(datasource, path_to_database, publish_mode, as_job=True)

print("Datasource published. Datasource ID: {0}".format(datasource.id))

The problem arises when I remove the limit of 1000 rows, and let all the rows through (approx 500K). I get the following errors. (can't paste the whole output)

 

ConnectionError: ('Connection aborted.', BrokenPipeError(32, 'Broken pipe'))

 

 Please help. Losing my mind over this.

답변 5개
  1. 2022년 9월 29일 오후 4:52

    @Tapaha Robati​ 

    I use the folliwing code, and it works:

    import tableauserverclient as TSC

    from pathlib import Path

     

    # server admin creds

    HOST="https://www.yourserver.com"

    #USER="youruser"

    #PWRD="yourpassword"

    TOKENNAME="tokenname"

    TOKENID="xyw==:55hP"

    #Use "" to default site

    SITE="Entrenamiento"

    #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)

    new_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()

    Maybe updating tsc:

    pip install --upgrade tableauserverclient

    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

0/9000