Python3 Unicodeencodeerror When Run via Synology Task Scheduler

Python3 UnicodeEncodeError when run via Synology task scheduler

When running from the command line, Python detects the encoding of the terminal and encodes Unicode text to the terminal in that encoding. When running under your task scheduler, Python is not detecting the output encoding and is defaulting to ascii.

It works in Python 2 when declaring the source encoding as utf8, because you are not using Unicode strings and print just sends the UTF-8-encoded byte string to the terminal. Your terminal is UTF-8, so it works.

You can override Python's default assumptions by setting the environment variable PYTHONIOENCODING=utf8 when running under the scheduler. This variable is available under all platforms.

Ref: PYTHONIOENCODING

Python: Running my program on synology nas as a task throws UnicodeEncodeError

After improving my googleing skills I found another answer on overflow and it turns out, that I needed to set my language in my tasks Script export LANG=en_US.utf8 now it all works.

My script now starts like this:

export PYTHONIOENCODING=utf8
export PYTHONTEXTENCODING=utf8
export LANG=en_US.utf8


Related Topics



Leave a reply



Submit