gpt4 book ai didi

sql-server - 将 SSRS 报告从 Python 导出为 PDF

转载 作者:行者123 更新时间:2023-12-04 01:36:34 24 4
gpt4 key购买 nike

我正在尝试从 Python 导出/打印/生成 SSRS 报告。看起来 SSPYRS 应该完全满足我的要求。但是,我收到一个错误并且找不到解决方法。

import sspyrs
try:
username= "user"
password = "pass"
params_multi = {'param1': value1, 'param2': value2, 'param3': value3}
myrpt = sspyrs.report("http://sqlserver/reportingserrver/reportsfolder/reportname", username, password, params_multi).download('PDF',fileloc)
except Exception as ex:
template = "An exception of type {0} occurred. Arguments:\n{1!r}"
message = template.format(type(ex).__name__, ex.args)

我收到以下错误:

Report Server does not allow usable data export methods. Update server settings/version to enable XML, Excel, or CSV export.



当我从浏览器运行相同的报告时,一切正常。我也可以毫无问题地从 .net 应用程序访问它。所以我怀疑这是权限问题。

我检查了 SQL Server 上的 reportserver.config 文件并启用了 PDF 呈现。我不知道我还能在哪里看。

任何帮助指导将不胜感激。

最佳答案

所以我必须使用 NTLM 身份验证才能让它在我的环境中为我工作。也许您可以使用和/或修改它?我是 SQL 人,不是 python,但这里是:

import requests
from requests_ntlm import HttpNtlmAuth

#change username to your username
filename = 'C:\\Users\\username\\Desktop\\report.pdf'

#change username and password to your network login
username = "username"
password = "password"
#url needs to be the special url found by going to the ReportServer, the one with &rs:Command=Render
url = "http://reportservername/ReportServer%2fReportFolder%2fReportName&rs:Command=Render&rs:Format=PDF"

r = requests.get(url, auth=HttpNtlmAuth(username, password))

print(r.status_code)

if r.status_code == 200:
with open(filename, 'wb') as out:
for bits in r.iter_content():
out.write(bits)

这篇文章对我有帮助: https://www.reddit.com/r/Python/comments/67xak4/enterprise_intranet_authentication_and_ssrs/

关于sql-server - 将 SSRS 报告从 Python 导出为 PDF,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/59305549/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com