Creating a new target with port_list


I’am new to Python things, so maybe a noob question, but I am stucking on it for hours now:
I want to create a new scan target using the gvm-pyshell in Linux.
Creating it without the port_list tag works fine:
gmp.create_target(“TARGETNAME”, True, hosts=“”)

But I want to use a specific port configuration, id: “4a4717fe-57d2-11e1-9a26-406186ea4fc5”

My first tought was, try it like this:
gmp.create_target(“TARGETNAME”, True, hosts=‘’, port_list=“4a4717fe-57d2-11e1-9a26-406186ea4fc5”)
But then it complains about a missing ID attribute:
ValueError: port_list requires an id attribute

When I try this, it complains about id (but that is logic):
gmp.create_target(“TARGETNAME”, True, hosts=‘’, port_list id=“4a4717fe-57d2-11e1-9a26-406186ea4fc5”)

I’ve tried this:
gmp.create_target(“TARGETNAME”, True, hosts=‘’, port_list_id=“4a4717fe-57d2-11e1-9a26-406186ea4fc5”)
That creates the target, but with the wrong port_list (the openvas default).

I’ve tried too many combinations with (), [], {} and so on, but didn’t find the working one. I think the solution is simple. Hope someone can help me.

Thanks :slight_smile:

Looking at the docs and code it should be

gmp.create_target(“TARGETNAME”, make_unique=True, hosts=[‘’], port_list_id=“4a4717fe-57d2-11e1-9a26-406186ea4fc5”)
1 Like

That doesn’t work too.

gmp.create_target(“TARGETNAME”, make_unique=True, hosts=[‘’], port_list_id=“4a4717fe-57d2-11e1-9a26-406186ea4fc5”)
Traceback (most recent call last):
File “”, line 1, in
File “gmp\”, line 328, in create_target
File “gmp\”, line 730, in createTargetCommand
File “src\lxml\lxml.etree.pyx”, line 1031, in lxml.etree._Element.text.set (src\lxml\lxml.etree.c:53209)
File “src\lxml\apihelpers.pxi”, line 715, in lxml.etree._setNodeText (src\lxml\lxml.etree.c:24404)
File “src\lxml\apihelpers.pxi”, line 703, in lxml.etree._createTextNode (src\lxml\lxml.etree.c:24267)
File “src\lxml\apihelpers.pxi”, line 1441, in lxml.etree._utf8 (src\lxml\lxml.etree.c:31461)
TypeError: Argument must be bytes or unicode, got ‘list’

No Issues here:

GVM Interactive Console 20.10.1 API 1.6.0. Type "help" to get information about functionality.
>>> resp = gmp.create_target("TARGETNAME3", make_unique=True, hosts=[''], port_list_id="4a4717fe-57d2-11e1-9a26-406186ea4fc5")
>>> from gvm.xml import pretty_print
>>> pretty_print(resp)
<create_target_response status="201" status_text="OK, resource created" id="70b6b00c-88a4-410a-9f50-94c5ac0946a4"/>


What gvm-tools and python-gvm versions are you using?

Just saw, that I have used python-gvm 1.6.0, but it also works with the current release:

GVM Interactive Console 20.10.2.dev1 API 20.11.0. Type "help" to get information about functionality.
>>> resp = gmp.create_target("TARGETNAME2", make_unique=True, hosts=[''], port_list_id="4a4717fe-57d2-11e1-9a26-406186ea4fc5")
>>> resp = gmp.create_target("TARGETNAME4", make_unique=True, hosts=[''], port_list_id="4a4717fe-57d2-11e1-9a26-406186ea4fc5")
>>> pretty_print(resp)
<create_target_response status="201" status_text="OK, resource created" id="63d47d0e-ec55-44fd-90da-4eea738b7455"/>
1 Like

File “gmp\”, line 328, in create_target
File “gmp\”, line 730, in createTargetCommand

Looks like gvm-tools < 2.0. That version is unsupported and outdated. Please update to the current one.


When I type help it shows up:
gvm-pyshell 1.4.1
I just downloaded the gvm shell from the website (so I guess it’s the latest?)

Don’t know where I can see the gvm-tools version.

What website?
Our packages can be installed with pip, or from source at and

1 Like

Please follow the documentation here You are using gvm-tools 1.4.1 which is very old.


On here:
It shows up: Python shell: gvm-pyshell.exe
From there I downloaded the Python shell.

Installed gvm-tools using pip install now, and it works. Thanks for all the replys.

1 Like