4

I am trying to export/print/generate SSRS reports from Python. It looks like SSPYRS should accomplish exactly what I am looking for. However, I get an error and can't find the ways around it.

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)

I get the following error:

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

When I ran the the same reports from the browser everything is working fine. I can also access it without any problems from .net applications. So I doubt it's a permissions issues.

I checked reportserver.config file on SQL Server and PDF rendering is enabled. I am not sure where else I can look.

Any help guidance will be greatly appreciated.

goryef
  • 1,337
  • 3
  • 22
  • 37
  • Is your params_multi assignment missing a single quote? ('param3) Or did you just copy/paste incorrectly? – LaraRaraBoBara Dec 12 '19 at 17:45
  • @FembotDBA. Just a typo. Thanks for pointing it out. – goryef Dec 12 '19 at 17:47
  • I tried a bit with that sspyrs module and get the same outcome. I'd perhaps write the author an email or download the file using the url and another python method? – LaraRaraBoBara Dec 12 '19 at 19:54
  • @FembotDBA. Thanks for trying. I didn't have much luck with url export. I need to be able to place PDF files in specific location and couldn't find that option. Do you know any other python methods to accomplish this? – goryef Dec 12 '19 at 20:05

1 Answers1

4

So I had to use NTLM authentication to get it to work for me in my environment. Maybe you could use and/or modify this? I am SQL person, not python, but here goes:

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)

This post helped me: https://www.reddit.com/r/Python/comments/67xak4/enterprise_intranet_authentication_and_ssrs/

LaraRaraBoBara
  • 628
  • 1
  • 6
  • 15