Opened 4 years ago
Closed 2 years ago
#19740 closed defect (fixed)
UnicodeDecodeError on takeScreenShotToArray with python 3
Reported by: | gim | Owned by: | |
---|---|---|---|
Component: | other | Version: | VirtualBox 6.1.10 |
Keywords: | Cc: | ||
Guest type: | other | Host type: | other |
Description
We have an exception on call display.takeScreenShotToArray with python 3
>>> data = display.takeScreenShotToArray(0, w, h, vboxMgr.constants.BitmapFormat_PNG) Traceback (most recent call last): File "<stdin>", line 1, in <module> File "<XPCOMObject method 'takeScreenShotToArray'>", line 3, in takeScreenShotToArray UnicodeDecodeError: 'utf-8' codec can't decode byte 0x89 in position 0: invalid start byte
Due to XIDL description it is returning octet array:
<method name="takeScreenShotToArray"> <desc> Takes a guest screen shot of the requested size and format and returns it as an array of bytes. </desc> <param name="screenId" type="unsigned long" dir="in"> <desc> The guest monitor to take screenshot from. </desc> </param> <param name="width" type="unsigned long" dir="in"> <desc> Desired image width. </desc> </param> <param name="height" type="unsigned long" dir="in"> <desc> Desired image height. </desc> </param> <param name="bitmapFormat" type="BitmapFormat" dir="in"> <desc> The requested format. </desc> </param> <param name="screenData" type="octet" dir="return" safearray="yes"> <desc> Array with resulting screen data. </desc> </param> </method>
In python 3 it must be bytes array not an unicode string. So here is error, probably: https://www.virtualbox.org/browser/vbox/trunk/src/libs/xpcom18a4/python/src/VariantUtils.cpp#L620
if (array_type == nsXPTType::T_U8) #if PY_MAJOR_VERSION <= 2 return PyString_FromStringAndSize( (char *)array_ptr, sequence_size ); #else return PyUnicode_FromStringAndSize( (char *)array_ptr, sequence_size ); // <----- here is #endif
So correct one when python 3:
return PyBytes_FromStringAndSize( (char *)array_ptr, sequence_size );
Change History (2)
comment:1 by , 4 years ago
comment:2 by , 2 years ago
Resolution: | → fixed |
---|---|
Status: | new → closed |
Thank you for reporting the issue. It should be fixed in VirtualBox 6.1.36. Please refer to https://www.virtualbox.org/wiki/Downloads page.
UP
This is really popular bug for python3 vboxapi users.
For example: https://github.com/sethmlarson/virtualbox-python/issues/111 and here: https://forums.virtualbox.org/viewtopic.php?f=34&t=98709
Still 5 weeks silence after specifying the exact location of this bug. Is VirtualBox developers alive!?