title: Python script encoding trouble when run in CRON job
body: <p>As many hopefully can relate, this encoding problem is driving me <em>mental</em>. I would really appreciate some light on this! </p>
  
  <p>End goal is to be able to run the same script.py from both terminal and cron, and from cron with <code>&gt; stdout.txt</code>. And needless to say, I'm having serious encoding troubles.</p>
  
  <p>My script.py runs fine from terminal thus: <code>python script.py</code>
  <br>It throws an error, however, when run from terminal thus: <code>python script.py &gt; stdout.txt</code>
  <br>It throws same error when run in cron, either way.</p>
  
  <p>I have a python script, entered in <code>crontab -e</code> as root.</p>
  
  <p>This is my script.py header:</p>
  
  <pre><code>#!/usr/bin/python
  # -*- coding: utf-8 -*-
  </code></pre>
  
  <p>This is my cron entry:</p>
  
  <pre><code>* * * * * python /home/ubuntu/parrot/script.py &gt; /home/ubuntu/parrot/stdout.txt
  </code></pre>
  
  <p>This is my stdout.txt (the relevant part):</p>
  
  <pre><code>Unexpected error!  (&lt;type 'exceptions.UnicodeDecodeError'&gt;, UnicodeDecodeError('ascii', 'blabla some weird text n\xc3\xa5r end', 54, 55, 'ordinal not in range(128)')) 
  </code></pre>
  
  <p>This is my env from terminal (the relevant part):</p>
  
  <pre><code>LANG=en_US.UTF-8
  </code></pre>
  
  <p>This is my env from cron (the relevant part):</p>
  
  <pre><code>LANG=en_US.UTF-8
  </code></pre>
  
  <p>This is the (first) line in script.py throwing the error:</p>
  
  <pre><code>print 'Posting @%s: %s' % (statusObj.user.screen_name.encode('ascii', 'replace'), statusObj.text.encode('utf-8', 'replace'))
  </code></pre>
  
  <p>Edit:
  <code>sys.getdefaultencoding()</code> returns <code>ascii</code></p>
  
  <p>Any help is greatly appreciated!</p>