def download(server, auth_token, site_id, workbook_id):
"""
Downloads the desired workbook from the server (temp-file).
'server' specified server address
'auth_token' authentication token that grants user access to API calls
'site_id' ID of the site that the user is signed into
'workbook_id' ID of the workbook to download
Returns the filename of the workbook downloaded.
"""
print("\tDownloading workbook to a temp file")
url = server + "/api/{0}/sites/{1}/workbooks/{2}/content".format(VERSION, site_id, workbook_id)
server_response = requests.get(url, headers={'x-tableau-auth': auth_token})
_check_status(server_response, 200)
# Header format: Content-Disposition: name="tableau_workbook"; filename="workbook-filename"
filename = re.findall(r'filename="(.*)"', server_response.headers['Content-Disposition'])[0]
with open(filename, 'wb') as f:
f.write(server_response.content)
return filename
评论列表
文章目录