Given the simple script:
#!/usr/bin/env python3
b = 'строка'.encode()
print(b.decode('utf-8'))
If I run it directly as python3 script.py
or /full/path/to/script.py
or indirectly through crontab (e.g. 0 0 * * * /full/path/to/script.py
) then it's executed normally (without errors). But when it's executed through fcrontab for the same $USER (with same job 0 0 * * * /full/path/to/script.py
) then Python 3.5.2 raise exception:
Traceback (most recent call last):
File "/full/path/to/script.py", line 4, in <module>
print(b.decode('utf-8'))
UnicodeEncodeError: 'ascii' codec can't encode characters in position 0-2: ordinal not in range(128)
How can it be possible? Why does Python try decode bytes as 'ascii' instead of 'utf-8'?