sethmlarson / virtualbox-python

Complete implementation of VirtualBox's COM API with a Pythonic interface.
https://pypi.org/project/virtualbox
Apache License 2.0
354 stars 75 forks source link

Connecting to Virtual Box server #118

Closed costimasca closed 1 year ago

costimasca commented 6 years ago
ENVIRONMENT
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])
sethmlarson commented 6 years ago

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?

costimasca commented 6 years ago

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

costimasca commented 6 years ago

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.

sethmlarson commented 6 years ago

I've never needed to call int() or str() on objects returned from vboxapi, may need to take a look at this.

sethmlarson commented 1 year ago

I no longer have time to maintain this library, so am closing this issue.