UnicodeEncodeError, ordinal not in range(128)?

Asked by teste on 2017-06-19

Hello, I'm gettin the error below, I was thinking that was some character with accents (maybe wrong ocr) but I all the info from ocr is printed as there is no accent.

[error] IDE: (org.sikuli.scriptrunner.JythonScriptRunner@6fa5acfe).runScript: Exception: UnicodeEncodeError: 'ascii' codec can't encode characters in position 177-180: ordinal not in range(128)

The code section is:

    print 'CHECKPOINT8'
    pro_list=sorted(profit.items(), key = lambda t:t[1])[-npares:]
    print 'CHECKPOINT9'
    pro_selec_dict=dict(pro_list)
    print "Pros: ", pro_selec_dict

So, the script is not printing 'CHECKPOINT9' but it is printing 'CHECKPOINT8', so the problem is in:

pro_list=sorted(profit.items(), key = lambda t:t[1])[-npares:]

"profit" is a dict, it is printed before when running, no error.
"npares" is a variable, it is printed before when running, as I use 4, (" [-4:]"), the list contains 4 items.

Please, someone knows what is the problem?

Thank you!

Question information

Language:
English Edit question
Status:
Solved
For:
Sikuli Edit question
Assignee:
No assignee Edit question
Solved by:
teste
Solved:
2017-06-25
Last query:
2017-06-25
Last reply:
2017-06-20
RaiMan (raimund-hocke) said : #1

since the IDE is UTF-8 aware, the problem must be with the
print 'CHECKPOINT9'

and not with
pro_list=sorted(profit.items(), key = lambda t:t[1])[-npares:]

With such errors, simply delete the line in question and rewrite.

teste (vpsa) said : #2

Hello RaiMan, thank you for the answer but it is/was not exactly the problem, I was running without the print 'CHECKPOINT9', as sikuli ide has no debug, I added this checkpoints to see exactly where is the problem, and, for some reason, today (1 day after) the problem do not happened, so my thoughts on what might have happened:

1)For some reason, OCR messed up on a string on the first running.
     - the script just carried over the string even without given a error on calculations (I don't know how).
     - As the script stopped, I runned again printing the dictionary and all the variables, (everything was fine)
     - Did not undestand the problem even running a dozen times.

[QUESTION] Sikuli carries a cache of the scripts?
If yes, MAYBE the first execution did ocurred the error and on the subsequents the error was being carried over by the cache.

RaiMan (raimund-hocke) said : #3

Yes, if some OCR was run before, that filled strings.

In the IDE the Python interpreter is is ONE session until IDE is stopped.

So to be sure you have to take care, that everything is initialized correctly, to avoid history from the last run.

teste (vpsa) said : #4

.