0

My python script run fine when ran manually but whenever run from cron job it throws UnicodeEncodeError: 'ascii' codec can't encode character '\u2122' in position 0: ordinal not in range(128)

myfile.py:

print(u"\u2122")

I am on macos high sierra and python version is 3.6.0

11
  • Can you paste your code?, that will help people know what is causing the issue. Commented Aug 19, 2019 at 4:35
  • @mishsx pasted. code is simple print Commented Aug 19, 2019 at 6:02
  • 1
    Just made it work by putting LC_ALL="en_US.UTF-8" on top of my crontab list. This is kind of hack, in other environment it works without this. Commented Aug 20, 2019 at 4:14
  • 1
    It struck me as earlier I had fixed PATH variable issues like this as well. Ideally in crontab file there should be nothing but jobs. So something at OS level must had to be rebuilt or reinstalled to make the fix proper Commented Aug 20, 2019 at 4:16
  • 1
    you should research on why it works in other environments but only this. Is there some setting that would be causing this? Sooner or later someone might face the same issue tomorrow, so make sure to put comments that would help the person who sees this next time. Commented Aug 20, 2019 at 4:22

1 Answer 1

1

Fixed it by putting on top of crontab:

LC_ALL="en_US.UTF-8"

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.