Answer the question
In order to leave comments, you need to log in
Why does coding in a python script work in the terminal, but not in cron?
Python 2.7
In the terminal, the script works fine, a file with a name in Cyrillic is created on the disk.
I run it in cron - it gives an error:
from io import open
def cache_set(key, val, path=None):
if path is None:
path = u'%s/cache' % os.getcwd()
if isinstance(key, str):
key = key.decode('utf8')
if isinstance(val, str):
val = val.decode('utf8')
elif not isinstance(val, unicode):
val = str(val).decode('utf8')
with open(u'{0}/{1}'.format(path, key), 'w', encoding="utf-8") as f:
f.write(val)
return True
key = u"Пермь"
val = u"..."
cache_set(key, val)
Traceback (most recent call last):
...
with open(u'{0}/{1}'.format(path, key), 'w', encoding="utf-8") as f:
IOError: [Errno 2] No such file or directory: '/home/master/cache/\xd0\x9f\xd0\xb5\xd1\x80\xd0\xbc\xd1\x8c'
PYTHONIOENCODING=utf8
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question