On 09/12/2014, at 8:29 PM, Nikolai Prokoschenko <[email protected]> wrote:
> Hi,
>
> On Tuesday, December 9, 2014 3:56:26 AM UTC+1, Graham Dumpleton wrote:
> The problem with the example is that the iterable returned should be over a
> sequence of bytes strings, not Unicode strings.
>
> I suppose using str(filename) in return statement is enough to be compliant?
One shouldn't use str() as that then depends on system encoding, which can
trust. You should use encode() method of Unicode string explicitly.
output.encode('UTF-8')
The encoding should actually be what every encoding the content type response
header said was being used.
>
> Can you also add in the following prior to the os.stat() and provide what the
> logs say:
>
> Of course (slightly anonymized):
>
> [Tue Dec 09 10:22:04 2014] [error] ('process_group', 'my_application')
> [Tue Dec 09 10:22:04 2014] [error] ('application_group', '')
> [Tue Dec 09 10:22:04 2014] [error] ('LANG', 'de_DE.UTF-8')
> [Tue Dec 09 10:22:04 2014] [error] ('LC_ALL', 'POSIX')
> [Tue Dec 09 10:22:04 2014] [error] ('sys.getdefaultencoding()', 'ascii')
> [Tue Dec 09 10:22:04 2014] [error] ('locale.getlocale()', ('de_DE', 'UTF8'))
> [Tue Dec 09 10:22:04 2014] [error] ('locale.getdefaultlocale()', (None, None))
> [Tue Dec 09 10:22:04 2014] [error] ('locale.getpreferredencoding()',
> 'ANSI_X3.4-1968')
> [Tue Dec 09 10:22:04 2014] [error] [client 10.250.205.193] mod_wsgi
> (pid=29728): Exception occurred processing WSGI script
> '/srv/my_application/app/wsgi.py'.
> [Tue Dec 09 10:22:04 2014] [error] [client 10.250.205.193] Traceback (most
> recent call last):
> [Tue Dec 09 10:22:04 2014] [error] [client 10.250.205.193] File
> "/srv/my_application/app/wsgi.py", line 28, in minimal_application
> [Tue Dec 09 10:22:04 2014] [error] [client 10.250.205.193]
> os.stat(filename)
> [Tue Dec 09 10:22:04 2014] [error] [client 10.250.205.193]
> UnicodeEncodeError: 'ascii' codec can't encode characters in position 5-7:
> ordinal not in range(128)
>
> I notice that LC_ALL is set to POSIX, which is probably where the error lies,
> getpreferredencoding() is probably just following that. I'll check again
> whether I've got anything wrong with the configuration.
The one that worried me is:
('locale.getpreferredencoding()', 'ANSI_X3.4-1968')
I really don't understand exactly how some of those get set and what they are
meant to indicate. It is entirely possible that my attempts to override them
are wrong.
if (daemon->group->lang) {
char *envvar = apr_pstrcat(p, "LANG=", daemon->group->lang, NULL);
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, wsgi_server,
"mod_wsgi (pid=%d): Setting lang to %s.",
getpid(), daemon->group->lang);
putenv(envvar);
}
if (daemon->group->locale) {
ap_log_error(APLOG_MARK, APLOG_DEBUG, 0, wsgi_server,
"mod_wsgi (pid=%d): Setting locale to %s.",
getpid(), daemon->group->locale);
setlocale(LC_ALL, daemon->group->locale);
}
So 'LANG' is set by setting the environment variable, but locale is set by
using setlocale() as it is already set by C libraries from LC_ALL environment
variable.
I can't remember why I though that setting LANG environment variable was
enough. Right now doing that doesn't seem right.
Just so have full context, can you provide the full WSGIDaemonProcess directive
line so can see everything that is being set.
Thanks.
Graham
--
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.