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
- JasperReports Server Web Services Guide - see Docs.
- Python 2.7 official documentation.
- 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]
Recommended Comments
There are no comments to display.