vm.errors.GvmResponseError: Response Error 400. Only command GET_VERSION is allowed before AUTHENTICATE

Hello everyone,
I have been using the code from the API documentation to build an automation scanning.
But when I’m running the code, it gives the error :
“gvm.errors.GvmResponseError: Response Error 400. Only command GET_VERSION is allowed before AUTHENTICATE”

Whereas, I am using the code following from the documentation (for the authentication to the automation scanning) in : https://python-gvm.readthedocs.io/en/latest/usage.html#using-gmp

Does anyone has the idea of why this is happening?

Hello lately i was having the same problem and i wasn’t able to find the solution anywhere so i started debugging the api code and i came up with a solution.

this is the code before the problem

        with Gmp(connection=connection, transform=transform) as gmp:
            gmp.authenticate(username, password)
        return gmp

the gmp object in this situation does not keep the authentication and you need to re-authenticate in all the methods that comes after.

        with Gmp(connection=connection, transform=transform) as gmp:
            return gmp

and after that to create a target for exemple do this

    username,password = "admin","password"
    gmp.authenticate(username, password)
    name = "targetName"
    response = gmp.create_target(name=name, hosts=["127.0.0.1"], port_range="T:1-500")