Import_report error

Good afternoon guys, I’m encountering an error when trying to import a report. When I use the get_report command it brings me the answer, however when passing this return to import_export I get the following error: ValueError: can only parse strings, then I used tostring inside the import_report, now I get the following message: An error occurred Response Error 400. A REPORT element is required, inside the output of get_report there is the tag report that the import_report requests in the documentation.

follow code below:

     from lxml.etree import tostring

     report = gmp.get_report(report_id="id_report_here")

    # import report
    importar = gmp.import_report(report=tostring(report), task_id="task_id_here")

I would like to know how can I import a report. please help me

Hey. You will need to have a valid formatted XML-Report that you have exported on a machine before. This report can than be imported by reading the XML-Report file and passing it to the import_report function.

AFAIK you need the outer <report></report> tag within you string. If you look carefully into an XML report, you can see, that it contains a lot of tags, that are ordered like this:

<report id="..." format_id="a994b278-1f62-11e1-96ac-406186ea4fc5" extension="xml" content_type="text/xml">
    <task id="...">
    <report id="...">

Everything in this XML needs to be in the string you want to import!

Edit: If you export your report with get_report(), you get additional XML, which you need to get rid of first:

<get_reports_response status="200" status_text="OK">
<report>HERE IS YOUR REPORT YOU WANT!</report>
  <filters id="">
    <term>apply_overrides=0 min_qod=70 first=1 rows=100 sort=name</term>
  <reports start="1" max="-2"/>

This can be done with the lxml.etree library. (e.g. with report.find('report') in your case)

1 Like