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
How to Route Webcam Video to Virtual Video Device on Linux (Via Opencv)
Linux Kernel: Copy_From_User - Struct with Pointers
Replace Text Between Two Lines with Contents of a File Stored in a Variable in Sed
How to Find Files with Same Size
Perl - Replace Every Nth (And Multiples) Occurrences of a Character with Another Character
Bash - Concatenating Variable on to Path
Perf Top Result About Nested Functions
Redirect Stdout and Stderr to File and Stderr to Stdout
Ssh Connection to Ubuntu Open Ssh-Server Requires Login on (Physical) Server via Password First
Sort Entries of Lines Using Shell
Why Count Differs Between Ls and Ls -L Linux Command
How to Get the Exit Status of the First Command in a Pipe
Export_Symbol in Kernel Module | Undefined Symbol During Insmod
How to Suspend and Resume a Sequence of Commands in Bash
Why Doesn't Linux Accept() Return Eintr
Batch Remove Substring from Filename with Special Characters in Bash