You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This gets the redirects property from the NatEngine object, which is
documented as follows:
readonly attribute wstring[] redirects
Array of NAT port-forwarding rules in string representation, in the
following format: "name,protocol id,host ip,host port,guest ip,guest
port".
When I run this test, I get:
python .\test.py
Traceback (most recent call last):
File ".\test.py", line 8, in
print(repr(nat.redirects))
File "C:\Work\Projects\vm\ve\lib\site-packages\comtypes__init__.py",
line 279, in getattr
return getattr(self, fixed_name)
File "C:\Work\Projects\vm\ve\lib\site-packages\comtypes\safearray.py",
line 218, in ctypes_from_outparam
return self[0]
File "C:\Work\Projects\vm\ve\lib\site-packages\comtypes\safearray.py",
line 209, in getitem
return self.unpack()
File "C:\Work\Projects\vm\ve\lib\site-packages\comtypes\safearray.py",
line 234, in unpack
result = self._get_elements_raw(num_elements)
File "C:\Work\Projects\vm\ve\lib\site-packages\comtypes\safearray.py",
line 301, in _get_elements_raw
import numpy.ctypeslib
ImportError: No module named 'numpy'
As far as I can tell, comtypes is interpreting the array of wstring
objects as a 2-dimensional array, and as a result thinks it needs
numpy.
Two suggestions here:
If numpy isn't available, fall back to something core Python can
handle like a tuple of tuples.
In this particular case, the code should be returning a tuple of
(Unicode) strings.
The equivalent code works with pywin32, for what it's worth.
The text was updated successfully, but these errors were encountered:
See PR #56. It seems to fix the issue for me, but I don't follow the refcounting semantics in comtypes so it's possible I've introduced a memory leak or similar. So a review by someone who actually understands the code would be useful!
From the mailing list: http://sourceforge.net/p/comtypes/mailman/message/32392260/
I've just hit an issue using comtypes to interact with Virtualbox.
Here's the simplest test case I can create:
import comtypes.client
import comtypes.gen.VirtualBox
vbox = comtypes.client.CreateObject('VirtualBox.VirtualBox')
machine = vbox.FindMachine('Ahri')
adapter = machine.getNetworkAdapter(0)
nat = adapter.NATEngine
print(repr(nat.redirects))
This gets the redirects property from the NatEngine object, which is
documented as follows:
readonly attribute wstring[] redirects
Array of NAT port-forwarding rules in string representation, in the
following format: "name,protocol id,host ip,host port,guest ip,guest
port".
When I run this test, I get:
As far as I can tell, comtypes is interpreting the array of wstring
objects as a 2-dimensional array, and as a result thinks it needs
numpy.
Two suggestions here:
handle like a tuple of tuples.
(Unicode) strings.
The equivalent code works with pywin32, for what it's worth.
The text was updated successfully, but these errors were encountered: