ClassCastException: class org.python.core.PyObjectDerived cannot be cast to class org.python.core.PyString

Asked by Singah

Hi,

I am between upgrades from 1.1.0 to 1.1.4 were I treated the screenshots as following:

ci = Screen(0).capture(Screen(0).getBounds())
with open(ci, 'rb') as file:
    encoded_string = base64.b64encode(file.read())

However, now getting the following error when doing this cast:

ClassCastException: java.lang.ClassCastException: class org.python.core.PyObjectDerived cannot be cast to class org.python.core.PyString (org.python.core.PyObjectDerived and org.python.core.PyString are in unnamed module of loader 'app')

Question information

Language:
English Edit question
Status:
Solved
For:
SikuliX Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
Last query:
Last reply:
Revision history for this message
Best RaiMan (raimund-hocke) said :
#1

Must have something to do with the base64 stuff, because this works:

ci = capture(0,0,10,10)
print "***** capture:", ci
fci = open(ci, 'rb')
print "***** open:", fci
sci = fci.read()
print ("***** read: ", sci)

and prints:
***** capture: C:\Users\RaiMan\AppData\Local\Temp\Sikulix_1880007\sikuliximage-1546535584204.png
***** open: <open file u'C:\\Users\\RaiMan\\AppData\\Local\\Temp\\Sikulix_1880007\\sikuliximage-1546535584204.png', mode 'rb' at 0xc>
('***** read: ', '\x89PNG\r\n\x1a\n\x00\x00\x00\rIHDR\x00\x00\x00\n\x00\x00\x00\n\x08\x02\x00\x00\x00\x02PX\xea\x00\x00\x00\x14IDATx^c\xf0\n\x89\xc4\x83\x180\x85F\xa5C"\x01i\xd4`}\n\x952\xa4\x00\x00\x00\x00IEND\xaeB`\x82')

Revision history for this message
Singah (singah) said :
#2

Thanks RaiMan, that solved my question.

Revision history for this message
Singah (singah) said :
#3

Thank you, the code above works fine and solves my issue.

It seems that this trigger the error:
Screen(0).capture(Screen(0).getBounds())

While this work perfectly fine:
capture(Screen(0).getBounds())

Revision history for this message
RaiMan (raimund-hocke) said :
#4

Thanks for feedback.

I will check and fix what is needed.

Revision history for this message
RaiMan (raimund-hocke) said :
#5

I revised the capture() parameter interpretation a bit:

capture(0) # or any other single number
capture("")

will capture the Screen(0) content and return the temp filename

If you want to capture another screen's content (multi monitor setup) use this:

capture(Screen(n))
where n is a valid screen number.

hence this works too:
capture(Screen(0))

for a complete descriptions of valid parameter settings see
https://sikulix-2014.readthedocs.io/en/latest/screen.html#capturing
(not yet finally revised)