Answer the question
In order to leave comments, you need to log in
Running a Python script in cron, how to output Cyrillic?
Greetings.
Input: on the server (Ubuntu), a python script (python 3) is run by cron.
Problem: as soon as Cyrillic comes across (for example: print('Hi')) - the script crashes with an exception like: "UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-7: ordinal not in range(128)".
If you run in the console - everything is ok.
In python 2, this was solved with a small hack:
import sys
reload(sys)
sys.setdefaultencoding('utf-8')
Answer the question
In order to leave comments, you need to log in
Add the magic comment # -*- coding: utf-8 -*- to the top of your script, like this:
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# some code
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question