I have a python script main.py , which reads my latest tweet using tweepy. I created a shell script looplauncher.sh, which call this python script:

cd /
cd home/pi/LCDinterface
sudo python main.py &
cd /

If I run python main.py or sh looplauncher.sh with or without sudo, my program runs fine. I pasted this line into cron: using sudo crontab -e

*/2 * * * * sleep 60 && sudo sh /home/pi/LCDinterface/looplauncher.sh >/home/pi/logs/loopcronlog 2>&1

The python script really does run at every 2 minutes ( I see it from the logs). But I can never get my tweet, If I run main.py manually I always get my tweet. I tried a lot of combination of sudo/ no sudo, added delay to give time for the connection. But nothing works so far. Can you help me with that? (I am doing this on a Raspberry Pi 3)

I got errors like this , when cron runs:

Traceback (most recent call last):
  File "main.py", line 49, in <module>
  File "main.py", line 32, in main
    tweet = getTweet('RaspProject')
  File "/home/pi/LCDinterface/twitterHelper.py", line 20, in getTweet
    print (tweet._json['text'])
UnicodeEncodeError: 'ascii' codec can't encode character u'\xe9' in position 32: ordinal not in range(128)

Running manually the scripts works fine. (Although I do really have some special hungarian letters in there, like éáőóű

1 Answer 1


Try adding this line before everything else in your crontab:

  • it did not solve my problem unfortunately, I printed out sys.executable, and it was always /usr/bin/python, but stil I always ended up getting decode errors, when running from cron. Anyway I switched to python3 made some modfications and now everything works. Thanks for your help. Apr 8, 2017 at 9:51

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .