sql-serverpython-3.xreporting-servicesexport-to-pdfreportserver

Exporting SSRS Reports to PDF from Python


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.


Solution

  • 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/