【问题标题】:Querying Tableau Server for exporting a view using python and REST API使用 python 和 REST API 查询 Tableau Server 以导出视图
【发布时间】:2021-11-25 13:25:50
【问题描述】:

我正在尝试使用 Python 将画面视图导出为图像/csv(没关系)。我用谷歌搜索,发现 REST API 在这里会有所帮助,所以我创建了一个个人访问令牌并编写了以下命令来连接:-

import tableauserverclient as TSC
from tableau_api_lib import TableauServerConnection
from tableau_api_lib.utils.querying import get_views_dataframe, get_view_data_dataframe

server_url = 'https://tableau.mariadb.com'
site = ''
mytoken_name = 'Marine'
mytoken_secret = '$32mcyTOkmjSFqKBeVKEZYpMUexseV197l2MuvRlwHghMacCOa'

server = TSC.Server(server_url, use_server_version=True)
tableau_auth = TSC.PersonalAccessTokenAuth(token_name=mytoken_name, personal_access_token=mytoken_secret, site_id=site)
with server.auth.sign_in_with_personal_access_token(tableau_auth):
    print('[Logged in successfully to {}]'.format(server_url))

成功进入并给出消息:-

[Logged in successfully to https://tableau.mariadb.com]

但是,我现在不知道如何使用 Python 访问画面工作簿。我在这里搜索:-

https://help.tableau.com/current/api/rest_api/en-us/REST/rest_api_ref_workbooks_and_views.htm

但无法在 python 中编写这些命令,例如 GET 或其他命令。

谁能帮忙?

【问题讨论】:

标签: python automation tableau-api export-to-csv tableau-desktop


【解决方案1】:

我假设您不知道要查找的视图的 view_id

在 with 块中的 print 之后添加此项将查询您网站上所有可用的视图;

 all_views, pagination_item = server.views.get()
 print([view.name for view in all_views])

然后在打印输出中找到您要查找的视图,并记下 view_id 以便像这样使用;

view_item = server.view.get_by_id('d79634e1-6063-4ec9-95ff-50acbf609ff5')

从那里,你可以得到这样的图像;

server.views.populate_image(view_item)
with open('./view_image.png', 'wb') as f:
    f.write(view_item.image)

tableauserverclient-python 文档也应该能帮到你很多

https://tableau.github.io/server-client-python/docs/api-ref#views

【讨论】:

    猜你喜欢
    • 2017-02-04
    • 2019-12-08
    • 2018-11-10
    • 2018-05-25
    • 2020-10-21
    • 1970-01-01
    • 2017-07-06
    • 2020-07-27
    • 1970-01-01
    相关资源
    最近更新 更多