Jump to content
JasperReports Library 7.0 is now available ×
  • REST in JasperReports server - exporting reports with python 2.7 and requests


    didier.davenne_1
    • Features: Reports, Web Services Version: v6.3, v6.3.1, v6.3.0 Product: JasperReports® Server

    Goals

    Sometimes, user don't want to use an Internet explorer, and want to get a report result just with a script or by clicking a button. So this little script show how to get locally the result of a report from the web server without using an explorer.

    Documentation

    1. JasperReports Server Web Services Guide - see Docs.
    2. Python 2.7 official documentation.
    3. Requests library for Python

    Short description

    you just have to define your server, the credentials, which report you want in which directory with the parameters needed and the extension of the export.

    All is in the URL you call.

    Example

    #!/usr/bin/python# -*- coding: utf-8 -*-# Coded by Didier DAVENNE 11/04/2017# for this example I used the requests library : https://pypi.python.org/pypi/requests# http://docs.python-requests.org/en/master/import requests# for this example I used an xlsx export, you can use every extension from the server : pdf, html, xls, csv, etc...r = requests.get('http://<your server address>:<server port>/jasperserver/rest_v2/reports/<Report Directory>/<your report Name>.xlsx?DateDebut=01/03/2017&DateFin=31/03/2017', auth=('jasperadmin','jasperadmin'))fd = open ('D:/Local_Output_Directory/<name of local file.xlsx', 'wb')fd.write(r.content)fd.close()[/code]

     

     


    User Feedback

    Recommended Comments

    There are no comments to display.



    Guest
    This is now closed for further comments

×
×
  • Create New...