Skip to content Skip to sidebar Skip to footer

Overwrite Python3 Default Encoder When Using Apache Server

I am running an apache server which serves a framework called ingenious Getting UnicodeDecodeError('ascii' when reading a file with hebrew chars. I've read that you can change th

Solution 1:

Read:

This explains issues around lang/locale.

You aren't using mod_wsgi daemon mode, but you should be as daemon mode is the recommended method.

Also go read the mod_wsgi documentation at:

Solution 2:

Python3 uses what local.getpreferredencoding returns as the encoding when opening files in text mode. I would suggest to add some logging and log the default encoding value to check whether it is the environment that's not configured properly.

It might be that there's a hard coded encoding parameter in the code somewhere. Can you show the stacktrace of the error and the corresponding code?

Depending on the deployment mechanism, it might be that the SetEnv configuration is not passed to Python. See http://ericplumb.com/blog/passing-apache-environment-variables-to-django-via-mod_wsgi.html for mod_wsgi deployments.

Similar to what is describe in that blog post, you have to modify the inginious-webapp.production file to get and set env vars manually. This is already done in the default inginious-webapp for some variables. Here you'd have to add in particular the PYTHONIOENCODING.

If you're running in mod_wsgi deamon mode, this might help http://modwsgi.readthedocs.io/en/develop/configuration-directives/WSGIDaemonProcess.html, in particular the lang or locale parameters.

Post a Comment for "Overwrite Python3 Default Encoder When Using Apache Server"