使用Python Migration SDK迁移Tableau时遇SignIn Error求助
尝试使用个人访问令牌(PAT)将本地Tableau Server迁移至Tableau Online时,出现SignIn Error(错误码401001)。已验证PAT及环境变量配置正确,但怀疑问题与URL或站点内容URL配置相关。
迁移代码
import tableau_migration import os from dotenv import load_dotenv import configparser from tableau_migration.migration_engine import PyMigrationPlanBuilder from tableau_migration.migration_engine_migrators import PyMigrator from threading import Thread load_dotenv() # Access environment variables on_prem_token_name = os.environ.get("on_prem_token_name") on_prem_private_token = os.environ.get("on_prem_private_token") cloud_token_name = os.environ.get("cloud_token_name") cloud_private_token = os.environ.get("cloud_private_token") # Read configuration from config.ini config = configparser.ConfigParser() config.read('config.ini') # Output all the inputs read by the config reader for section in config.sections(): print(f"Section: {section}") for option in config.options(section): value = config.get(section, option) first_three_letters = value[:3] if len(value) >= 3 else value print(f" Option: {option}, Value: {first_three_letters}, Len: {len(value)}") def migrate_single_workbook(): # Initialize migration plan builder and migrator plan_builder = PyMigrationPlanBuilder() migrator = PyMigrator() # Read configuration from config.ini config = configparser.ConfigParser() config.read('config.ini') # Build the migration plan plan = plan_builder \ .from_source_tableau_server( server_url=config['SOURCE']['URL'], site_content_url=config['SOURCE']['SITE_CONTENT_URL'], access_token_name=config['SOURCE']['ACCESS_TOKEN_NAME'], access_token=on_prem_private_token)\ .to_destination_tableau_cloud( pod_url=config['DESTINATION']['URL'], site_content_url=config['SOURCE']['SITE_CONTENT_URL'], access_token_name=config['DESTINATION']['ACCESS_TOKEN_NAME'], access_token=cloud_private_token ) \ .for_server_to_cloud() \ .with_tableau_id_authentication_type() \ .with_tableau_cloud_usernames(config['USERS']['EMAIL_DOMAIN']) \ .build() # Execute the migration plan results = migrator.execute(plan) # Handle migration results for result in results: print(result) return plan # Create a thread to run the migration migration_thread = Thread(target=migrate_single_workbook) migration_thread.start() # Wait for the migration to complete or handle interruption while True: try: migration_thread.join(1) break except KeyboardInterrupt: print("Migration interrupted. Cleaning up...") # Cleanup resources if needed break
错误信息
An error occurred during migration. Error: Tableau.Migration.Api.Rest.RestException: An error was returned from the Tableau API:
URL:
Code: 401001
Summary: Signin Error
Detail: Error signing in to Tableau Server
环境信息
- Python 3.11.5
- 运行于AWS云VM
config.ini配置
[SOURCE] URL = https://tableau.website.com/ SITE_CONTENT_URL = #/site/projects/87 ACCESS_TOKEN_NAME = access_token_name [DESTINATION] URL = https://prod-us-b.online.tableau.com/#/site/tableaucompanywebsite SITE_CONTENT_URL = ACCESS_TOKEN_NAME = cloud_access_token_name [USERS] EMAIL_DOMAIN = company.com
用户不确定URL及站点内容URL的配置是否正确(尤其是包含#的格式),也怀疑SITE_CONTENT_URL配置有误,请求指导排查并解决该登录错误。
核心问题在于URL和SITE_CONTENT_URL的格式配置错误,Tableau API不接受包含#及后续路径的URL,且站点内容URL需要提取正确的站点标识,同时代码中存在一处配置错误,以下是分步修复方案:
1. 修正URL配置(去除#及后续内容)
Tableau API的基础URL只需要根域名,不需要浏览器地址栏中#之后的前端路由部分:
- SOURCE URL:保留
https://tableau.website.com/(如果原URL带#路径,直接截断到根域名) - DESTINATION URL:将
https://prod-us-b.online.tableau.com/#/site/tableaucompanywebsite修改为https://prod-us-b.online.tableau.com/
2. 修正SITE_CONTENT_URL配置
SITE_CONTENT_URL需要的是站点的内容URL名称(站点唯一标识),不是完整浏览器路由:
- SOURCE SITE_CONTENT_URL:从原路径
#/site/projects/87中提取站点标识,这里应为projects;若不确定,可通过Tableau Server REST API调用GET /api/3.20/sites获取站点的contentUrl字段 - DESTINATION SITE_CONTENT_URL:当前为空是错误的,提取原路径
#/site/tableaucompanywebsite中的tableaucompanywebsite作为值
修正后的config.ini示例:
[SOURCE] URL = https://tableau.website.com/ SITE_CONTENT_URL = projects ACCESS_TOKEN_NAME = access_token_name [DESTINATION] URL = https://prod-us-b.online.tableau.com/ SITE_CONTENT_URL = tableaucompanywebsite ACCESS_TOKEN_NAME = cloud_access_token_name [USERS] EMAIL_DOMAIN = company.com
3. 修复代码中的配置错误
在to_destination_tableau_cloud方法中,错误地使用了源站点的内容URL作为目标站点配置,需改为目标站点的对应值:
.to_destination_tableau_cloud( pod_url=config['DESTINATION']['URL'], site_content_url=config['DESTINATION']['SITE_CONTENT_URL'], # 修改为DESTINATION配置 access_token_name=config['DESTINATION']['ACCESS_TOKEN_NAME'], access_token=cloud_private_token )
4. 额外验证步骤
- 确认PAT权限:源和目标的PAT需至少包含
site:read、site:write、workbook:read、workbook:write等迁移所需权限 - 网络连通性:AWS VM需能访问源Tableau Server和Tableau Online的443端口,可通过
curl测试API连通性:# 测试源服务器 curl https://tableau.website.com/api/3.20/serverinfo # 测试Tableau Online curl https://prod-us-b.online.tableau.com/api/3.20/serverinfo
内容的提问来源于stack exchange,提问作者eccadena

