die einfache Skript Gegeben:Warum löst der Python3-Interpreter UnicodeEncodeError nur aus, wenn er über fcron ausgeführt wird?
#!/usr/bin/env python3
b = 'строка'.encode()
print(b.decode('utf-8'))
Wenn ich es direkt als python3 script.py
oder /full/path/to/script.py
oder indirekt durch crontab (z 0 0 * * * /full/path/to/script.py
), dann ist es normal ausgeführt laufen (ohne Fehler). Aber wenn es durch fcrontab für die gleichen $ USER (mit gleichem Job 0 0 * * * /full/path/to/script.py
) dann Python 3.5.2 raise Ausnahme der ausgeführt wird:
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)
Wie kann es möglich sein? Warum versucht Python Bytes als 'ASCII' anstelle von 'UTF-8' zu dekodieren?
hier Siehe https://wiki.python.org/moin/PrintFails –
Oh, es ist wirklich Problem mit nur 'print' Funktion wegen Gebietsschema, das für fcron-Set (in Mein Fall fcron hat locales 'POSIX' anstelle von * .UTF-8) ... Danke! – kupgov