Are you using mod_wsgi daemon mode as you should?

Have you set the lang/local options to WSGIDaemonProcess directive?

Or are you using mod_wsgi-express?

A problem with Apache is that inherits an effectively blank user environment, 
thus it often defaults to ASCII encoding rather than anything sensible.

If using daemon mode, use the lang/locale settings to set more sensible 
defaults.

If using embedded mode it is a bit more complicated as you have to set 
environment variables as part of Apache status scripts.

These issues are explain to a degree in the Django documentation at:

https://docs.djangoproject.com/en/1.8/howto/deployment/wsgi/modwsgi/#if-you-get-a-unicodeencodeerror
 
<https://docs.djangoproject.com/en/1.8/howto/deployment/wsgi/modwsgi/#if-you-get-a-unicodeencodeerror>

although they only mention the use of environment variables as a solution.

The ‘envvars’ file also only exists for Apache Software Foundation layout for 
Apache httpd installations. Linux distributions screw around with it and impose 
their own layout and ‘envvars’ can’t be used, thus needs to be in Linux system 
specific startup scripts.

Better to use daemon mode as you always should be.

http://blog.dscpl.com.au/2012/10/why-are-you-using-embedded-mode-of.html 
<http://blog.dscpl.com.au/2012/10/why-are-you-using-embedded-mode-of.html>

Then you can override it more easily.

http://blog.dscpl.com.au/2014/09/setting-lang-and-lcall-when-using.html

Graham

> On 27 Aug 2015, at 1:54 pm, [email protected] wrote:
> 
> Dear All,
> 
> I'm developing a test application in Python using Apache2 and mod_wsgi.
> Versions are Apache/2.4.7 mod_wsgi/4.4.13 Python/3.4.0.
> I also connect to the same server via PuTTY and use the same Python 3.4.0 for 
> short interactions, trials, etc.
> 
> I ran into a problem 
> (https://groups.google.com/forum/#!topic/comp.lang.python/8PgHk_bm84U) where 
> I had to open a file by explicitly telling to encode with UTF-8, as in:
> 
>      f = open('testresults', 'a', encoding='utf-8')
> 
> to avoid an encoding error when exchanging french characters like in `René` ( 
> e with acute accent). And yet, all my set-ups for HTML, Javascript, PuTTY, 
> Linux, Python, ... indicate UTF-8.
> 
> What I found is that the interpreter and the Python daemon set-up by mod_wsgi 
> give me 2 different answers:
> 
> In interactive mode:
> 
>     rse@Alibaba:~/test$ python
>     Python 3.4.0 (default, Jun 19 2015, 14:18:46)
>     [GCC 4.8.2] on linux
>     Type "help", "copyright", "credits" or "license" for more information.
>     >>> from os import environ
>     >>> from locale import getpreferredencoding
>     >>> environ["LANG"]
>     'en_US.UTF-8'
>     >>> getpreferredencoding()
>     'UTF-8'
>     >>>
> 
> In script mode, I get exactly  the same:
> 
>     rse@Alibaba:~/ims/test$ cat environ.py
>     #! /usr/bin/env python
>     # -*- coding: utf-8 -*-
> 
>     from os import environ
>     from locale import getpreferredencoding
> 
>     lang = environ["LANG"]
>     code = getpreferredencoding()
> 
>     f = open('envresults', 'a')
>     f.write(lang + '\n')
>     f.write(code + '\n')
>     f.close()
> 
>     rse@Alibaba:~/test$ python environ.py
>     rse@Alibaba:~/test$ cat envresults
>     en_US.UTF-8
>     UTF-8
>     rse@Alibaba:~/test$
> 
> But when I write the same few statements within my application function 
> definition:
>     def application(environ, start_response):
>         from os import environ
>         [...etc...]
> I receive a different answer, namely:
>     ANSI_X3.4-1968
>     C
> 
> I have read again all possible mod-wsgi Configuration Directives but could 
> not find one about encoding or environment variables.
> 
> I also suspected my Python installation (there is still a Python 2.7.6 
> available next to the 3.4.0 version) but launching it interactively or 
> running the same script gives me the same answer, viz. en_US.UTF-8, UTF-8.
> 
> In what direction should I search ? Apache2 ? ...
> 
> Any hint, suggestion, ... will be most welcome. Thanks in advance.
> 
> Regards,
> René
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "modwsgi" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected] 
> <mailto:[email protected]>.
> To post to this group, send email to [email protected] 
> <mailto:[email protected]>.
> Visit this group at http://groups.google.com/group/modwsgi 
> <http://groups.google.com/group/modwsgi>.
> For more options, visit https://groups.google.com/d/optout 
> <https://groups.google.com/d/optout>.

-- 
You received this message because you are subscribed to the Google Groups 
"modwsgi" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/modwsgi.
For more options, visit https://groups.google.com/d/optout.

Reply via email to