tableau / server-client-python

A Python library for the Tableau Server REST API
https://tableau.github.io/server-client-python/
MIT License
655 stars 421 forks source link

Publishing workbook results in 403131 Forbidden error #1294

Open anth-dinosaur opened 11 months ago

anth-dinosaur commented 11 months ago

Describe the bug When publishing a workbook, I am receiving the following error:

 403131: Forbidden
                A workbook with the same name is currently being published or modified. Wait until the task completes before you try again.

But, the workbook is not being currently published or modified. I can run the same code on v0.28 and get the error and then immediately run the v0.25 version and get the expected result.

Note: the workbook does actually seem to be published to Tableau Server, even though an error is being generated: I do see an updated modified time on Tableau Server. It appears that v0.28 makes an async request that it initially thinks fails, so it retries and gets the "currently being published" message, and then the original asnyc request returns successfully. See logs at the bottom.

Versions Details of your environment, including:

The test workbook I am publishing here is very small, only 137kb.

To Reproduce Publish workbook as below:

auth = tsc.PersonalAccessTokenAuth(tableauPATName, tableauPATToken)
server = tsc.Server(tableauServer, use_server_version=True)
with server.auth.sign_in(auth):
  new_wb = tsc.WorkbookItem(name=publishName, project_id=targetProj.id)
  new_job = server.workbooks.publish(
      workbook_item=new_wb, file=fileName, mode="Overwrite", 
  )
  deploy_url = new_job.webpage_url
  print(
      "Workbook published. JOB ID: {0} | URL: {1}".format(
          new_job.id, new_job.webpage_url
      )
  )

Results Running the above with tableauserverclient v0.28 results in:

 403131: Forbidden
                A workbook with the same name is currently being published or modified. Wait until the task completes before you try again.

after downgrading to v0.25:

pip install --force-reinstall -v "tableauserverclient==0.25"

Then, I get expected results:

Workbook published. JOB ID: {job_id} | URL: https://{tableau_server_url}/#/workbooks/{wb_num}

Logger Logs (omitted beginning sign-in parts for clarity)

v0.25

INFO:tableau.endpoint.workbooks:Publishing {wb_name}.twb to server
DEBUG:tableau.endpoint.workbooks:Request xml: bytearray(b'--06574cc61668fec5fab403a912c47365\r\nContent-Disposition: form-data; name="request_payload"; filename=""\r\nContent-Type: text/xml\r\n\r\n<tsRequest><workbook name="test"><project id="{projectID}" /></workbook></tsRequest>\r\n--06574cc61668fec5fab403a912c47365\r\nContent-Disposition: form-data; name="tableau_workbook"; filename="{wb_name}.twb"\r\nContent-Type: application/octet-stream\r\n\r\n<?xml version=\'1.0\' encoding=\'utf-8\' ?>\r\n\r\n<!-- build 20223.23.0710.1931                               -->\r\n<workbook original-version=\'18.1\' source-build=\'2022.3.8 (20223.23.0710.1931)\' version=\'18.1\' xml:base=\'https://{tableau_server_url}\' xmlns:user=\'http://www.tableausoftware.com/xml/user\'>\r\n  <document-format-change-manifest>\r\n    <_.fcp.AnimationOnByDefault.true...AnimationOnByDefault />\r\n    <ISO8601DefaultCalendarPref />\r\n    <_.fcp.MarkAnimation.true...MarkAnimation />\r\n    <_.fcp.ObjectModelEncapsulateLegacy.true...ObjectModelEncapsulateLegacy />\r\n    <_.fcp.ObjectModelTable..[redacted]') 
DEBUG:tableau.endpoint:request method post, url: https://{tableau_server_url}/api/3.17/sites/{site_id}/workbooks?workbookType=twb&overwrite=true
DEBUG:urllib3.connectionpool:https://{tableau_server_url}:443 "POST /api/3.17/{site_id}/workbooks?workbookType=twb&overwrite=true HTTP/1.1" 201 None
INFO:tableau.endpoint.workbooks:Published test (ID: {wb_id})
DEBUG:tableau.endpoint:request method post, url: https://{tableau_server_url}/api/3.17/auth/signout
DEBUG:urllib3.connectionpool:https://{tableau_server_url}:443 "POST /api/3.17/auth/signout HTTP/1.1" 204 0
INFO:tableau.endpoint.auth:Signed out

v0.28

INFO:TSC:Publishing {wb_name}.twb to server
DEBUG:TSC:Request xml: bytearray(b'--6247c19d2fe1871fc2b7f5a5cb05027d\r\nContent-Disposition: form-data; name="request_payload"; filename=""\r\nContent-Type: text/xml\r\n\r\n<tsRequest><workbook name="test"><project id="{projectID}" /></workbook></tsRequest>\r\n--6247c19d2fe1871fc2b7f5a5cb05027d\r\nContent-Disposition: form-data; name="tableau_workbook"; filename="{wb_name}.twb"\r\nContent-Type: application/octet-stream\r\n\r\n<?xml version=\'1.0\' encoding=\'utf-8\' ?>\r\n\r\n<!-- build 20223.23.0710.1931                               -->\r\n<workbook original-version=\'18.1\' source-build=\'2022.3.8 (20223.23.0710.1931)\' version=\'18.1\' xml:base=\'https://{tableau_server_url}\' xmlns:user=\'http://www.tableausoftware.com/xml/user\'>\r\n  <document-format-change-manifest>\r\n    <_.fcp.AnimationOnByDefault.true...AnimationOnByDefault />\r\n    <ISO8601DefaultCalendarPref />\r\n    <_.fcp.MarkAnimation.true...MarkAnimation />\r\n    <_.fcp.ObjectModelEncapsulateLegacy.true...ObjectModelEncapsulateLegacy />\r\n    <_.fcp.ObjectModelTable..[redacted]') 
DEBUG:TSC:request method post, url: https://{tableau_server_url}/api/3.17/sites/{site_id}/workbooks?workbookType=twb&overwrite=true
DEBUG:TSC:[23:36:50] Begin blocking request to https://{tableau_server_url}/api/3.17/sites/{site_id}/workbooks?workbookType=twb&overwrite=true
DEBUG:TSC:[23:36:51] Async request returned: received None
DEBUG:TSC:None
DEBUG:TSC:[23:36:51] Async request failed: retrying
DEBUG:TSC:[23:36:51] Begin blocking request to https://{tableau_server_url}/api/3.17/sites/{site_id}/workbooks?workbookType=twb&overwrite=true
DEBUG:urllib3.connectionpool:https://{tableau_server_url}:443 "POST /api/3.17/sites/{site_id}/workbooks?workbookType=twb&overwrite=true HTTP/1.1" 403 None
DEBUG:TSC:[23:36:52] Call finished
DEBUG:TSC:[23:36:52] Request complete
DEBUG:TSC:Response status: <Response [403]>
DEBUG:TSC:request method post, url: https://{tableau_server_url}/api/3.17/auth/signout
DEBUG:TSC:[23:36:52] Begin blocking request to https://{tableau_server_url}/api/3.17/auth/signout
DEBUG:urllib3.connectionpool:https://{tableau_server_url}:443 "POST /api/3.17/auth/signout HTTP/1.1" 204 0
DEBUG:TSC:[23:36:52] Call finished
DEBUG:TSC:[23:36:52] Request complete
DEBUG:urllib3.connectionpool:https://{tableau_server_url}:443 "POST /api/3.17/sites/{site_id}/workbooks?workbookType=twb&overwrite=true HTTP/1.1" 201 None
DEBUG:TSC:[23:36:53] Call finished
DEBUG:TSC:[23:36:53] Request complete
DEBUG:TSC:[23:36:53] Async request returned: received <Response [204]>
DEBUG:TSC:Response status: <Response [204]>
DEBUG:TSC:Server response from https://{tableau_server_url}/api/3.17/auth/signout
INFO:TSC:Signed out
bshea5 commented 11 months ago

Thanks for opening this issue. I'm also hitting the same problem after recently upgrading to 0.28.

joshv2 commented 10 months ago

Using the as_job=True parameter in .publish will allow for successful publishing even in the latest version but from what I see catching errors in async is difficult which is a downside of this approach.

zrayadh commented 10 months ago

I have come across this issue while trying to Overwrite a non-existant workbook (mode=TSC.Server.PublishMode.Overwrite). By changing to mode=TSC.Server.PublishMode.CreateNew it fixed the issue.