Opened 4 years ago

Closed 21 months 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


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">
        Takes a guest screen shot of the requested size and format
        and returns it as an array of bytes.
      <param name="screenId" type="unsigned long" dir="in">
          The guest monitor to take screenshot from.
      <param name="width" type="unsigned long" dir="in">
          Desired image width.
      <param name="height" type="unsigned long" dir="in">
          Desired image height.
      <param name="bitmapFormat" type="BitmapFormat" dir="in">
          The requested format.
      <param name="screenData" type="octet" dir="return" safearray="yes">
          Array with resulting screen data.

In python 3 it must be bytes array not an unicode string. So here is error, probably:

if (array_type == nsXPTType::T_U8)
                return PyString_FromStringAndSize( (char *)array_ptr, sequence_size );
                return PyUnicode_FromStringAndSize( (char *)array_ptr, sequence_size ); // <----- here is

So correct one when python 3:

return PyBytes_FromStringAndSize( (char *)array_ptr, sequence_size );

Change History (2)

comment:1 by gim, 4 years ago


This is really popular bug for python3 vboxapi users.

For example: and here:

Still 5 weeks silence after specifying the exact location of this bug. Is VirtualBox developers alive!?

comment:2 by galitsyn, 21 months ago

Resolution: fixed
Status: newclosed

Thank you for reporting the issue. It should be fixed in VirtualBox 6.1.36. Please refer to page.

Note: See TracTickets for help on using tickets.

© 2023 Oracle
ContactPrivacy policyTerms of Use