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]. 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.
