从Python将SSRS报告导出为PDF

问题描述 投票:2回答:1

我正在尝试从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不允许使用可用的数据导出方法。更新服务器设置/版本以启用XML,Excel或CSV导出。

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

我在SQL Server上检查了reportserver.config文件,并启用了PDF呈现。我不确定我还能去哪里。

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

sql-server python-3.x reporting-services export-to-pdf reportserver
1个回答
3
投票

因此,我必须使用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/

© www.soinside.com 2019 - 2024. All rights reserved.