如何直接从 Salesforce Lightning 下载 CSV 格式的报告?

How to download a report as a CSV directly from Salesforce Lightning?

我正在创建一个 Python 脚本,用于以 CSV 格式从 Salesforce 下载报告。

我的脚本在 Salesforce Classic 中运行良好。但是,我需要让它为 Lightning Experience 工作。我正在使用 simple-salesforce Python 包来访问我们的组织。对于 SF Classic,我输入一个结构如下的 link:https://my-company.my.salesforce.com/my_report_id?view=d&snip&export=1&enc=UTF-8&xf=csv

脚本基本上是这样的:

from simple-salesforce import Salesforce
import requests
import pandas as pd
import csv
from io import StringIO

sf = Salesforce(username="my_username", password="my_password",
                security_token="my_token")
sf_org = "https://my_company.my.salesforce.com/"
report_id = "0000" # Some report id

sf_report_loc = "{0}{1}?view=d&snip&export=1&enc=UTF-8&xf=csv".format(sf_org, report_id)

response = requests.get(sf_report_loc, headers=sf.headers, cookies={"sid": sf.session_id})
new_report = response.content.decode("utf-8")
df = pd.read_csv(StringIO(new_report)) # Save the report to a DataFrame.

每当我切换到 Lightning 时,link 无效并且我被重定向。有没有办法让这个在 Lightning 中工作?

尝试使用 isdtp 参数。在经典中,它用于强制查看没有侧边栏或 header 的页面,例如将 isdtp=vw 添加到随机页面,看看会发生什么。

https://my_company.my.salesforce.com/00O.....?isdtp=p1&export=1&enc=UTF-8&xf=csv ?

(不知道 'p1' 是什么,但这是我在 Chrome 的下载历史记录中看到的,作为报告来源 URL 的一部分)