Page 1 of 1

[Python] NameError: name 'LockType' is not defined

PostPosted: 22. Jan 2019, 16:22
by GenghisKhan
Hello everyone,

I am trying to create snapshots in python through vboxapi, but since I never used vboxapi before, I feel a bit lost when I dive in documentation and examples from python, java and C# to know the right steps to accomplish this.

So I came to this script where I am getting,

Code: Select all   Expand viewCollapse view
NameError: name 'LockType' is not defined

Where I am calling LockType in a possible wrong way or due to missing library importation, but I really dont know how to set it.

Here is my actual script:

Code: Select all   Expand viewCollapse view
import datetime
import vboxapi

def virtual_machines_master():
    inicial_date =
    virtualboxmanager = vboxapi.VirtualBoxManager(None, None)
    vbox = virtualboxmanager.getVirtualBox()
    session = virtualboxmanager.getSessionObject(vbox)
    session.console.takeSnapshot('Snapshot '+inicial_date.strftime("%y%m%d"), 'Snapshot taken through vboxapi')

if __name__=="__main__":

System specs:
- Python 3.6.5
- VirtuaBox 5.2.16
- Windows 10

Re: [Python] NameError: name 'LockType' is not defined

PostPosted: 23. Jan 2019, 18:26
by klaus
There are some examples in the SDK manual, and also uses several enum consts. None of these look like what you do. Seems you copied something from a Java example or some such.

For Python the access to enum constants works with vboxmgr.constants.LockType_Shared and the like. vboxmgr is the object returned by the VirtualBoxManager(...) constructor.

Oh, and there's also vboxmgr.openMachineSession(...) which creates a session and by default gets a lock of type LockType_Shared, plus a matching closeMachineSession(). This is used by