golismero / openvas_lib

OpenVAS connector for versions 6, 7, 8 and 9
BSD 3-Clause "New" or "Revised" License
80 stars 98 forks source link

get_results returns TypeError: Expected str or file, got '<type 'Element'>' instead #17

Open liuyoyi opened 7 years ago

liuyoyi commented 7 years ago

openvas_results = scanner.get_report_id(scan_id) print openvas_results

Returns

TypeError: Expected str or file, got '<type 'Element'>' instead

Why??????

codenside commented 6 years ago

I dig into the code actually report_parser expecting a file or string as argument, but the get_result method giving and Element object. so I comment it out the parse part

screenshot from 2018-05-16 20-53-39

and I wrote my own function to parse the result as follow

def parse(res):
    output = []
    results = res.getchildren()

    for result in results:
        children = result.getchildren()
        obj = {}
        for child in children:
            obj[child.tag] = child.text
        output.append(obj)
    return output

I can now call it like this

parse(scanner.get_results(scan_id))

which returns a python list contains all results

I don't know how to fix the original parse function, I believe they will patch it soon :sparkle:

Geniussylvain commented 5 years ago

Hello, I would like to know where do you write this code in the __init___.py file ?

Thanks

Sylvain

thinksabin commented 5 years ago

i'm facing same issue:

File "/Users/openvas-stuffs/lib/python2.7/site-packages/openvas_lib/ompv7.py", line 1099, in get_report_xml raise TypeError("Expected string, got %r instead" % type(report_id)) TypeError: Expected string, got <type 'NoneType'> instead