0

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:

barcode.generate_barcode("ean", "1341341234234")

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.

enter image description here

If I run the same setup with django ./manage.py runserver comand. The resulting image is fine, no special characters added.

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.

I would like to try a newer version of mod_wsgi but compilation fails.

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.

In Apache conf.d/charset:

AddDefaultCharset UTF-8

In my vhost additionally:

AddDefaultCharset UTF-8

In apache2/envvars:

export LANG='en_US.UTF-8'
export LC_ALL='en_US.UTF-8'

Envvars is used in apache runlevel script:

if [ -z "$APACHE_ENVVARS" ] ; then
    APACHE_ENVVARS=$APACHE_CONFDIR/envvars
fi

I also tried to hardcode overwrite env vars in the runlevel script.

In my wsgi file:

import sys
reload(sys)
sys.setdefaultencoding('utf-8')

But nothing seems to help. My image is still generated with broken encoding.

phlebas
  • 1,210
  • 2
  • 13
  • 24
  • may be something related with apache configuration? http://stackoverflow.com/questions/913869/how-to-change-the-default-encoding-to-utf-8-for-server – Walty Yeung Jun 18 '13 at 09:34
  • I have already tried this. Update my question accordingly – phlebas Jun 18 '13 at 09:44
  • 1
    Verify somehow that apache2/envvars is even used. On many Linux distros it isn't used and you need to added those lines to files within the init.d startup area for the Apache service. – Graham Dumpleton Jun 18 '13 at 09:54
  • I have adapted my question. envvars is used by default. Hardcode overwrite in initscript didn't help either – phlebas Jun 18 '13 at 14:12
  • @phlebas Have you fixed this issue? Thanks. – zzxwill Apr 12 '17 at 12:48

2 Answers2

0

An upgrade of mod_wsgi to version 3.4.0 fixed it.

phlebas
  • 1,210
  • 2
  • 13
  • 24
0

You can use the option lang or locale to the WSGIDaemonProcess clause.

See in https://modwsgi.readthedocs.io/en/develop/configuration-directives/WSGIDaemonProcess.html

am70
  • 591
  • 6
  • 8