title: Django WSGI Python Encoding
body: <p>I have a strange issue with my Django Apache Wsgi setup. I recently moved my site to a different server. Unfortunately now the encoding is somewhat messed up. When I run a command like this:</p>
  
  <p><code>barcode.generate_barcode("ean", "1341341234234")</code></p>
  
  <p>the resulting image will show some special character between every digit, typically for some endocing issue. I guess it is using two bytes instead of one to represent each char or something similar.</p>
  
  <p><img src="https://i.stack.imgur.com/9vSbW.png" alt="enter image description here"></p>
  
  <p>If I run the same setup with django <em>./manage.py runserver</em> comand. The resulting image is fine, no special characters added.</p>
  
  <p>So I came to the conclusion this must be something with my apache2/mod_wsgi setup. But the versions are identical to my old setup, i.e. debian 6, apache2.2, mod_wsgi 3.3.2.</p>
  
  <p>I would like to try a newer version of mod_wsgi but compilation fails.</p>
  
  <p>Can anyone point me in the right direction to where this encoding error might have its cause? To my understanding the WSGI context somehow loads the entire python script with a wrong encoding, otherwise I cannot explain why a hardcoded string would turn out wrong on an image.</p>
  
  <p>In Apache conf.d/charset:</p>
  
  <pre><code>AddDefaultCharset UTF-8
  </code></pre>
  
  <p>In my vhost additionally:</p>
  
  <pre><code>AddDefaultCharset UTF-8
  </code></pre>
  
  <p>In apache2/envvars:</p>
  
  <pre><code>export LANG='en_US.UTF-8'
  export LC_ALL='en_US.UTF-8'
  </code></pre>
  
  <p>Envvars is used in apache runlevel script:</p>
  
  <pre><code>if [ -z "$APACHE_ENVVARS" ] ; then
      APACHE_ENVVARS=$APACHE_CONFDIR/envvars
  fi
  </code></pre>
  
  <p>I also tried to hardcode overwrite env vars in the runlevel script.</p>
  
  <p>In my wsgi file:</p>
  
  <pre><code>import sys
  reload(sys)
  sys.setdefaultencoding('utf-8')
  </code></pre>
  
  <p>But nothing seems to help. My image is still generated with broken encoding. </p>