server-client-python icon indicating copy to clipboard operation
server-client-python copied to clipboard

TSC.SubscriptionItem, Payload is either malformed or incomplete. (0x5CE10192 : Specifying subscription attachments not allowed.)

Open gdrau opened this issue 1 year ago • 10 comments

Hello, I'm trying to create a subscription for a user on a view. I put this piece of code, schedule_id = '60c392fc-d902-44b0-92cf-cfa3b512630f' user_id = df[0].values[i] # Create the new SubscriptionItem object with variables from above. new_sub = TSC.SubscriptionItem('EssaiGD', schedule_id, user_id, target)

    # (Optional) Set other fields. Any of these can be added or removed.
    new_sub.attach_image = True
    new_sub.attach_pdf = True
    new_sub.message = "You have an alert!"
    new_sub.page_orientation = TSC.PDFRequestOptions.Orientation.Portrait
    new_sub.page_size_option = TSC.PDFRequestOptions.PageType.A4
    new_sub.send_if_view_empty = True

    # Create the new subscription on the site you are logged in.
    new_sub = server.subscriptions.create(new_sub)

I launch it and when I have the error it gives me 0x5CE10192 : Specifying subscription attachments not allowed.

THanks

Version : Product version: 2024.2.0 REST API version: 3.23 Build number: 20242.24.0711.1807 Python 3.10.6

gdrau avatar Jul 29 '24 14:07 gdrau

From the REST API documentation:

If subscriptions to attachments are disabled in Tableau server or site settings, then making a request that sets attachImage to false will cause an error.

jorwoods avatar Jul 30 '24 16:07 jorwoods

the parameters are true and not false in my script. So when I manually create the subscription or when I use a request it works. So I don't understand why it doesn't work

gdrau avatar Jul 30 '24 16:07 gdrau

image

gdrau avatar Jul 30 '24 16:07 gdrau

What happens if you set image to True, pdf to False, and remove the pdf specific options? Try the simplest case first.

jorwoods avatar Jul 30 '24 16:07 jorwoods

image the same

gdrau avatar Jul 30 '24 20:07 gdrau

image

gdrau avatar Jul 30 '24 20:07 gdrau

image

gdrau avatar Jul 30 '24 20:07 gdrau

?? Help me :-)

gdrau avatar Aug 26 '24 13:08 gdrau

My minimally reproducible example works. edit: Also attaching image. Still works.

# /// script
# requires-python = ">=3.10
# dependencies = [
#   "tableauserverclient>=0.32.0",
#   "python-dotenv"
# ]
# ///

import os

from dotenv import load_dotenv
import tableauserverclient as TSC

load_dotenv()

auth = TSC.PersonalAccessTokenAuth(
    token_name=os.environ["TABLEAU_TOKEN_NAME"],
    personal_access_token=os.environ["TABLEAU_PAT"],
    site_id=os.environ["TABLEAU_SITE"]
)

server = TSC.Server(os.environ["SERVER_ADDRESS"], use_server_version=True)
with server.auth.sign_in(auth):
    workbook = server.workbooks.filter(name="Team Metrics")[0]
    target = TSC.Target(workbook.id, "workbook")

    # Pick a random schedule for testing purposes
    sched = next(s for s in TSC.Pager(server.schedules) if s.schedule_type == TSC.ScheduleItem.Type.Subscription)
    
    sub = TSC.SubscriptionItem("message", schedule_id=sched.id, user_id=server.user_id, target=target)
    sub.attach_image = True
    sub.attach_pdf = True
    sub.page_orientation = TSC.PDFRequestOptions.Orientation.Portrait
    sub.page_size_option = TSC.PDFRequestOptions.PageType.A4
    sub.send_if_view_empty = True
    
    sub = server.subscriptions.create(sub)

jorwoods avatar Aug 27 '24 12:08 jorwoods

@gdrau what API version are you using in your script? This error message will also be returned if you are specifying an API version below 3.5, when the feature was implemented.

jacalata avatar Sep 20 '24 08:09 jacalata

I created a sample for subscriptions and verified that it succeeds with the current server version, and fails using 2.4. https://github.com/tableau/server-client-python/pull/1487

jacalata avatar Oct 04 '24 23:10 jacalata