Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
martijnkuiper
Frequent Visitor

Power BI REST API ExportTo MHTML leads to a base64 encoded file

I am using a Python Notebook to export Paginated Reports to an HTML file. Now it works fine for CSV files, I get clear and readable CSV back, the same goes for IMAGE with the format set to PNG. But when I set the format to MHTML as per the documentation I am getting a long error response about my headers, followed by a succesfull download of a file with .html extension. If I open it however it doesn't look like HTML:

 

MIME-Version: 1.0
Content-Type: multipart/related;
boundary="----=_NextPart_01C35DB7.4B204430"
X-MSSQLRS-ProducerVersion: V
 
This is a multi-part message in MIME format.
 
------=_NextPart_01C35DB7.4B204430
Content-ID: <filename>
Content-Disposition: inline;
filename="filename"
Content-Type: text/html;
name="filename";
charset="utf-8"
Content-Transfer-Encoding: base64
 
PCFET0NUWVBFIEhUTUwgUFVCTElDICItLy9XM0MvL0RURCBIVE1MIDQuMDEgVHJhbnNpdGlvbmFs
aXB0LVR5cGUiIGNvbnRlbnQ9InRleHQvamF2YXNjcmlwdCIvPjxNRVRBIEhUVFAtRVFVSVY9Ikxv....[this goes on for a long time]

VEg9IjAiIEhFSUdIVD0iMTAwJSI+PC9URD48L1RSPjwvVEFCTEU+PC9ESVY+PC9ESVY+PC9ib2R5
PjwvaHRtbD4=

------=_NextPart_01C35DB7.4B204430--

 

I have tried several bodies, but the documentation is lacking for the formatSettings for Paginated Reports:

martijnkuiper_0-1741966165395.png

And with empty formatSettings and I also left the formatSettings completely out, but there is no difference. The response from the download action for this html file is as follows:

 

Failed to parse headers (url=https://api.powerbi.com:443/v1.0/myorg/groups/[REDACTED]/reports/[REDACTED]/exports/Mi9CbG9iSWRWMi1m...😞 [NoBoundaryInMultipartDefect()], unparsed data: '' Traceback (most recent call last): File "/home/trusted-service-user/cluster-env/trident_env/lib/python3.11/site-packages/urllib3/connection.py", line 464, in getresponse assert_header_parsing(httplib_response.msg) File "/home/trusted-service-user/cluster-env/trident_env/lib/python3.11/site-packages/urllib3/util/response.py", line 88, in assert_header_parsing raise HeaderParsingError(defects=defects, unparsed_data=unparsed_data) urllib3.exceptions.HeaderParsingError: [NoBoundaryInMultipartDefect()], unparsed data: ''

 

And the file itself remains unreadable base64 encoded and it seems to be partial. Now I have a hunch that there maybe is a formatSetting to get a UTF-8 / UTF-16 HTML file, but it also seems odd that that would have to be specified. How can I find out why my HTML file is not properly formatted as readable (and usable) HTML?

 

Adding just ?rdl:format=MHTML to a URL of a Paginated Report returns a readable HTML file. But when using the REST API, I cannot find why it keeps sending me base64 encoded partial files.

 

Thanks for helping me out

Martijn Kuiper

1 ACCEPTED SOLUTION

Ok, plan B.  Use Power Query to decode the Base64 data.  Text.FromBinary(Binary.FromText(payload),Encoding.Base64)

View solution in original post

5 REPLIES 5
v-prasare
Community Support
Community Support

@martijnkuiperAs we haven’t heard back from you, we wanted to kindly follow up to check if the solution provided for your issue worked? or let us know if you need any further assistance here?

 

@lbendlin  , Thanks for your promt response

 

 

Thanks,

Prashanth Are

MS Fabric community support

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly and give Kudos if helped you resolve your query

lbendlin
Super User
Super User

in your call try to add an

accept = "text/html"

directive in the header, not the body.

 

Accept - HTTP | MDN

 

Unfortunately this has had no effect for me. Adding the Accept text/html didn't change anything for me. I then switched it up, following your documentation, to */*:

martijnkuiper_0-1742408541550.png

 

But this also didn't lead to a different outcome

Ok, plan B.  Use Power Query to decode the Base64 data.  Text.FromBinary(Binary.FromText(payload),Encoding.Base64)

I in stead used Python base64 library (since moving in PowerQuery within my script would be quite some redesign) and I now get the same HTML content as I am getting when I export the paginated report to HTML from the browser view.

 

I can't imagine this is working as intended, but I at least now have an HTML file!

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.