Forums

UnicodeDecodeError just in the Scheduler

When I run a python script from the scheduler, I get the following error:

Traceback (most recent call last):
File "/home/hurrial2/haberbenzerlik/haberbenzerlik.py", line 21, in <module>
    tr_stop_words = fileutils.getlinelist(path_to_resources + "tr/tr_stop_words2.txt")
  File "/home/hurrial2/datautils/datautils/fileutils.py", line 7, in getlinelist
    linelist = f.read().splitlines()
  File "/home/hurrial2/.virtualenvs/dj17/lib/python3.4/encodings/ascii.py", line 26, in decode
    return codecs.ascii_decode(input, self.errors)[0]
    UnicodeDecodeError: 'ascii' codec can't decode byte 0xc4 in position 29: ordinal not in range(128)
2015-03-08 19:02:23 -- Completed task, took 16.00 seconds, return code was 1.

My command: python3.4 /home/hurrial2/haberbenzerlik/haberbenzerlik.py

I tried to run in the scheduler: /home/hurrial2/.virtualenvs/dj17/bin/python /home/hurrial2/haberbenzerlik/haberbenzerlik.py

However those commands work without any error in the bash. I could not understand what is the difference or how I can correct it. Does anybody now?

I came across the following forum post: https://www.pythonanywhere.com/forums/topic/734/ but it does not have a proper solution either.

Thanks for your time.

Ali

May I ask what locale settings/unicode encoding do you want to use?

Looking at your scheduled tasks command, I see that you copied the LC_CTYPE=uk_UA.utf-8 from the forum post you referenced which is for Ukraine.

Hi Conrad,

My locale is:

    echo $LC_CTYPE

    en_US.utf-8

Although I process Turkish text, my script run without errors when I applied the suggestion:

    LC_CTYPE=uk_UA.utf-8 python3 /home/vanderloos/testrun.py

I think the correct locale for processing Turkish characters is tr_TR.UTF-8

Thanks, I updated it and it runs very well. I would still like to find a permanent solution for that difference between the consoles and scheduler.

Ali

You should set your locale in the console as well!

For the scheduler, maybe your should say have a script that sets your local for you, and then runs whatever you pass in as a parameter?

Yes, I can create such a script to set the locale and run my programs.

Ali