Automate export from Power BI file to PDF

I have a power BI report that uses SQL server and python script as the data sources. I need to export this to PDF and send it out on a daily basis to a few selected people.

Is there a way to do the following using python:

  1. Open the Power BI desktop file
  2. Hit the "Refresh" button to refresh the datasets
  3. Click on the "Export to PDF" option
  4. Mail the exported PDF to a group of people

I know that something similar can be achieved using Power BI Service but when I published the power BI report and installed a personal gateway, I got the following error: enter image description here

I had installed the personal mode gateway and entered my email address but when I opened the gateway again, it asks me to sign in every time (I'm not sure if this is normal.)

enter image description here


Solution 1:

The gateway is fine as long as you have it set as "Running" in your dataset settings, once you login, you don't have to open it again: enter image description here

For exporting the Power Bi report as PDF, there is an API dedicated to that https://docs.microsoft.com/en-us/rest/api/power-bi/reports/export-to-file The drawback is that you need Power BI Premium to use it.

In case you had the Premium, then you could send a Post request using Python's module "Requests" to extract the pdf using that report's ID.