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

Asked by Singah on 2019-01-03

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:
Sikuli Edit question
Assignee:
No assignee Edit question
Solved by:
RaiMan
Solved:
2019-01-04
Last query:
2019-01-04
Last reply:
2019-01-03
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')

Singah (singah) said : #2

Thanks RaiMan, that solved my question.

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())

RaiMan (raimund-hocke) said : #4

Thanks for feedback.

I will check and fix what is needed.

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)