﻿id,summary,reporter,owner,description,type,status,component,version,resolution,keywords,cc,guest,host
19740,UnicodeDecodeError on takeScreenShotToArray with python 3,gim,,"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 );
}}}

 
",defect,closed,other,VirtualBox 6.1.10,fixed,,,other,other
