Forums

Scheduled Task UnicodeEncodeError

Hello,

When I run a script from the bash terminal or from using the Save & Run button my script runs fine, however when I set it as a scheduled task I get the error...

UnicodeEncodeError: 'ascii' codec can't encode character u'\xa3' in position 0: ordinal not in range(128)

Any thoughts on why this might be the case?

I thinks scheduled tasks run with slightly different defaults for character encoding.

If you explicitly specify your encodings and decodings, you'll probably be able to avoid the error:

print(my_thing.encode('utf8'))

Hey Harry,

Thanks for this, that sorted it issue, would you say it's fairly standard to always add .encode('utf8') to strings?

I have been reading quite a bit in character sets and to be honest it's taking a while to sink in!

I don't know about standard, but it's a good idea -- it saves you from unexpected unicode errors like the one you just found. Python 3 sort of forces you to do it a bit more...

Thanks mate