Forum Discussion

martijnkuiper's avatar
martijnkuiper
Frequent Visitor
1 year ago
Solved

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:

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/Mi9CbG9iSWRWMi1mYTJjOTY5Yy00NmZlLTRiYzktYjNkZS00NjFmZTE1YmExMTN3UHY3ZGxOLXlXVXpxU3N2THlGWk5YMlN2Yzl4MnRQeUJaWk4tQ2x0Lg==/file😞 [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

  • lbendlin's avatar
    lbendlin
    1 year ago

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

5 Replies

    • martijnkuiper's avatar
      martijnkuiper
      Frequent Visitor

      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 */*:

       

      But this also didn't lead to a different outcome

      • lbendlin's avatar
        lbendlin
        Super User

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

  • v-prasare's avatar
    v-prasare
    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