'NoneType' object has no attribute 'encode'

Hii,

I am using scripts provided under gvm-tools, when I run the gvm-script command for pdf report generation I get an error as "‘NoneType’ object has no attribute ‘encode’ ".
The syntax I followed for scanning is $ gvm-script --gmp-username name --gmp-password pass \ ssh --hostname scripts/scan-new-system.gmp.py <host_ip>

The syntax I followed for pdf report is $ gvm-script --gmp-username name --gmp-password pass \ ssh --hostname scripts/pdf-report.gmp.py <report_id> <pdf_file>

Can someone please help me solving this error.
The screenshot of output is as shown below-

Please someone reply

I’m quoting from https://community.greenbone.net/t/all-hosts-are-with-127-0-0-x-ip-after-removing-some-older-reports/7160/3:

You can’t expect an answer within 24 hours. All people here are answering questions on a voluntary basis. Even all employees of Greenbone. Please be patient and if you need a reaction within 24 hours please think about professional and payed support!

By referring previous post I got an updated script for pdf-report.gmp.py. I did the correction of content line but again got an error as “Incorrect Padding”.The script i used is as follows:

from base64 import b64decode
from pathlib import Path


def check_args(args):
    len_args = len(args.script) - 1
    if len_args < 1:
        message = """
        This script requests the given report and saves it as a pdf file locally.
        It needs one parameters after the script name.

        1. <report_id>     -- ID of the report
    
        Optional a file name to save the pdf in.

        Example:
        $ gvm-script --gmp-username name --gmp-password pass \ssh --hostname   
        <gsm> scripts/pdf-report.gmp.py <report_id> <pdf_file>
         """
        print(message)
        quit()

def main(gmp, args):
    # check if report id and PDF filename are provided to the script
    # argv[0] contains the script name
    check_args(args)

    report_id = args.argv[1]
    if len(args.argv) == 3:
        pdf_filename = args.argv[2]
    else:
        pdf_filename = args.argv[1] + ".pdf"

    pdf_report_format_id = "c402cc3e-b531-11e1-9163-406186ea4fc5"

    response = gmp.get_report(
       report_id=report_id, report_format_id=pdf_report_format_id
    )

    report_element = response[0]
   # get the full content of the report element
    content = "".join(report_element.itertext())

   # convert content to 8-bit ASCII bytes
   binary_base64_encoded_pdf = content.encode('ascii')

   # decode base64
   binary_pdf = b64decode(binary_base64_encoded_pdf)

   # write to file and support ~ in filename path
   pdf_path = Path(pdf_filename).expanduser()

   pdf_path.write_bytes(binary_pdf)

   print('Done. PDF created: ' + str(pdf_path))

if __name__ == '__gmp__':
   main(gmp, args)

Error: Incorrect Padding

See https://github.com/greenbone/gvm-tools/issues/327 for further discussion.

2 Likes