print region.text(): UnicodeEncodeError --- use uprint()

Asked by Cam

Hi. Pls Help.

I'm receiving error "UnicodeEncodeError ( 'ascii' codec can't encode character u'\u2018' in position 1: ordinal not in range(128) )"
when I run the code below:

I receive the error on line "print(text)".

    Settings.OcrTextRead = True
    reg=find(Pattern("1473260102302.png").targetOffset(-9,50))

    text = reg.text()
    print(text) ********I receive error here*******

    if "1080" in text:
        if "59.94" in text:
            print("it is 1080 and 59.94")
        else:
            print("Not 59.94")
    else:
        print("Not 1080")

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
RaiMan (raimund-hocke) said :
#1

apparently the returned text contains UTF-8/non-ASCII characters.

the normal print cannot be used in this case.

use
uprint(text)

instead.

Revision history for this message
Cam (cfamili) said :
#2

Thank you very much for quick response.
It worked but I also get extra lines.

Do you know how to get rid of the extra lines?

'-'-aacbH Forward ll'I—'CopyDL ---EXTRA LINE
Reference mode: 1080i 59.94
it is 1080 and 59.94

-----Original Message-----
From: <email address hidden> [mailto:<email address hidden>] On Behalf Of RaiMan
Sent: Wednesday, September 07, 2016 3:27 PM
To: Camellia Famili
Subject: Re: [Question #385878]: UnicodeEncodeError ( 'ascii' codec can't encode character u'\u2018' in position 1: ordinal not in range(128) )

Your question #385878 on Sikuli changed:
https://answers.launchpad.net/sikuli/+question/385878

    Status: Open => Answered

RaiMan proposed the following answer:
apparently the returned text contains UTF-8/non-ASCII characters.

the normal print cannot be used in this case.

use
uprint(text)

instead.

--
If this answers your question, please go to the following page to let us know that it is solved:
https://answers.launchpad.net/sikuli/+question/385878/+confirm?answer_id=0

If you still need help, you can reply to this email or go to the following page to enter your feedback:
https://answers.launchpad.net/sikuli/+question/385878

You received this question notification because you asked the question.

----------------------------------------------
This e-mail and any attachments may contain information that is confidential to Ross Video.
If you are not the intended recipient, please notify me immediately by replying to this message. Please also delete all copies. Thank you.

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

Sorry, but you have to live with the quirks of the current OCR implementation.

Make your experiments with the size and shape of the regions, where you want to get the text, until you get something, that you can live with.

Revision history for this message
Cam (cfamili) said :
#4

Ok that's ok. Thank you very much for your help!

Revision history for this message
Hina (hina-amir) said :
#5

for me it worked
uprint(reg2.text())