virtualbox-python
virtualbox-python copied to clipboard
Connecting to Virtual Box server
ENVIRONMENT
- Operating System: Ubuntu 18.04
- Python version: 2.7
- VirtualBox version: 5.2.18
- VirtualBox SDK version: 5.2.18
- Location where VirtualBox SDK is installed: /sdk
- pyvbox version: 1.3.2
- [x] Happens in latest
master
branch?
SUMMARY
The issue appears when trying to connect to a remote VirtualBox server. Instantiating the virtualbox.VirtualBox class fails.
STEPS TO REPRODUCE
Have a Virtual Box server running with the "vboxwebsrv.sh" script.
Run the following code:
import os
import sys
os.environ['VBOX_SDK_PATH'] = '/sdk'
sys.path.append('/usr/lib/virtualbox')
import virtualbox
from virtualbox import WebServiceManager
from virtualbox import VirtualBox
manager = WebServiceManager(url='http://localhost:18083')
vbox = VirtualBox(manager=manager)
print(vbox)
EXPECTED RESULTS
<virtualbox.library_ext.vbox.IVirtualBox object at 0x7fc020453bd0>
ACTUAL RESULTS
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/virtualbox/library_ext/vbox.py", line 20, in __init__
self._i = manager.get_virtualbox()._i
File "/usr/local/lib/python2.7/dist-packages/virtualbox/__init__.py", line 175, in get_virtualbox
return VirtualBox(interface=self.manager.getVirtualBox())
File "/usr/local/lib/python2.7/dist-packages/virtualbox/library_ext/vbox.py", line 25, in __init__
this_version = ".".join(self.version.split('.')[0:2])
AttributeError: String instance has no attribute 'split'
PROPOSED SOLUTION
Change the lines of code in library_ext/vbox.py from:
this_version = ".".join(self.version.split('.')[0:2])
build_version = ".".join(self.version.split(library.vbox_version)[0:2])
to:
this_version = ".".join(self.version.__str__()split('.')[0:2])
build_version = ".".join(self.version.__str__().split(library.vbox_version)[0:2])
String
? Where does that instance come from? I've never seen anything like this before. Could you show me the output when you run python -m pip freeze
?
This is the output for python -m pip freeze
:
numpy==1.15.1
Pillow==5.2.0
pytesseract==0.2.4
pyvbox==1.3.2
vboxapi==1.0
ZSI==2.1a1
The String class is defined in sdk/bindings/webservice/python/lib/VirtualBox_wrappers.py
After I solved the issue yesterday by calling the __str__()
I continued my work to modify my code to work remotely. Sadly, however I noticed a pattern of needing to call __str__
or __int__
on objects returned from VirtualBox_wrappers. Another example would be calling session.console.display.get_screen_resolution(0)
.
Inside the get_screen_resolution function, the
self._call("getScreenResolution", in_p=[screen_id])
function returns:
(<VirtualBox_wrappers.UnsignedInt instance at 0x10b2f4200>, <VirtualBox_wrappers.UnsignedInt instance at 0x10b2f40e0>, <VirtualBox_wrappers.UnsignedInt instance at 0x10b2f4248>, <VirtualBox_wrappers.Int instance at 0x10b2f4290>, <VirtualBox_wrappers.Int instance at 0x10b2f42d8>, <VirtualBox_wrappers.GuestMonitorStatus instance at 0x10b2f4320>)
not actual integers as expected.
I've never needed to call int() or str() on objects returned from vboxapi, may need to take a look at this.