Can't restore object from trashcan. Why?

Hello.
I have a latest release of GSE.
I try to restore from trashcan by this code:

gmp.restore(id=my_task_id)

But i got error:

gmp.restore(id=my_task_id)
TypeError: restore() got an unexpected keyword argument 'id'

I didnt undstand, why ‘id’ is a “unexpected keyword” ?

For details about your issue please read https://realpython.com/python-kwargs-and-args/

See https://python-gvm.readthedocs.io/en/latest/api/gmpv9.html#gvm.protocols.gmpv9.Gmp.restore for the gmp.restore API.

1 Like

Hi, tnx for reply.
I’ve read links that you provided, i rewrite my code as:

gmp.restore(entity_id=my_task_id)

Where “my_task_id” var really contains the id of task moved to trashcan.
But i have new error:
Error in response. Failed to find resource 'b5beea97-ca23-48c7-a858-056fd6534424'", <Element restore_response at 0x7f8cd4c4e448>

Now what i do wrong ?

Mistyped id?
Or the resource vanished from the trashcan in the meantime? It’s 4d since your OP, so maybe some auto cleaning kicked in?
How did you originally know it’s there? If you use the same method to know if it’s still there, is it still there?
Or maybe it’s part of something which is missing. Is the trash you try to recover partially restored?

Yes, there problem was wrong id.
I tried search as:
gmp.get_tasks(filter='name=Web test scan')

But, id of task ‘test scan’ returns, not id of moved task ‘Web test scan’

Then I renamed ‘Web test scan’ to ‘Web_test_scan’, and now i try to find moved task to trashcan by this code:

tasks = gmp.get_tasks(filter='name=Web_test_scan')
  for task in tasks.xpath('task'):
      my_task_id = task.get('id')
      print (task.find('name').text)
      print ('---- ' + my_task_id + ' ----')

But it doesn’t find task ‘Web_test_scan’ when it is in the trashcan.
When the task ‘Web_test_scan’ in restored, code above find ID perfectly.

How to find id of deleted task correctly ?

2 Likes

Please take a deep look at the API docs

https://python-gvm.readthedocs.io/en/latest/api/gmpv9.html#gvm.protocols.gmpv9.Gmp.get_tasks

tasks = gmp.get_tasks(filter='name=Web_test_scan', trash=True)
3 Likes

Thanks very much.

I can’t get used to https://python-gvm.readthedocs.io instead of https://docs.greenbone.net/API/GMP/.
The “docs.greenbone.net” is slightly hard reading for me. i just skipped ‘trash’ keyword.

1 Like

Please always take a look at https://python-gvm.readthedocs.io/ first. python-gvm does some things differently which aren’t easy to fix in the protocol. Also the docs for python-gvm are updated more often.

4 Likes