Thinking back about this some more and realising in one case you are talking
about environment variables, and in another case you are talking about per
request WSGi variables, then the behaviour is probably correct as required by
the WSGI specification. At least to the extent that the WSGI specification can
be applied, since these per request variables are Apache specific.
Anyway, the issue goes back to Python 2 and the updates to WSGI for Python 3.
In Python 2 various things passed in the WSGI environ dictionary related to a
request were passed as normal strings (which are actually byte strings, not
unicode strings, which were different in Python 2). Since the WSGI server can't
know what encoding the WSGI application wants to use, it will take whatever it
gets and passes through the raw byte stream. If a WSGI application wanted to
interpret that as UTF-8, it was up to the WSGI application to decode the byte
string and convert it to a unicode string.
In Python 3, the same issue still existed in that the WSGI server would not
know what encoding a WSGI application wanted applied. At the same time though,
the default string in Python 3 was a unicode capable string.
Now it wasn't practical in Python 3 to pass through variables as byte strings
as the range of operations you could do on byte strings was very limited. Thus
the rule for WSGI under Python 3 was that the WSGI server was required to take
the underlying byte stream and convert it to the unicode capable default string
as ISO-8859-1 (Latin-1). It was then up to the WSGI application to convert that
to another string with the correct encoding. Since it was a unicode string at
that point, to do that it would need to do.
value.encode('ISO-8859-1').decode('UTF-8')
So this little dance was necessary. It was a bit ugly, but that is just how it
was defined.
So apply that and see if you get what you expect.
Graham
> On 18 Aug 2022, at 6:09 pm, '[email protected]' via modwsgi
> <[email protected]> wrote:
>
> Hi Graham!
>
> Graham Dumpleton schrieb am Donnerstag, 18. August 2022 um 09:15:32 UTC+2:
> Can you use the recommended daemon mode of mod_wsgi and when doing so set the
> lang/locale to what you use.
>
> See the lang/locale options in:
>
> https://modwsgi.readthedocs.io/en/master/configuration-directives/WSGIDaemonProcess.html
>
> <https://modwsgi.readthedocs.io/en/master/configuration-directives/WSGIDaemonProcess.html>
>
> Unfortunately, this doesn't change the behaviour…
>
> I changed the WSGI settings in the Apache VirtualHost config to
>
> WSGIDaemonProcess testserver_proc lang=en_US.UTF-8
> locale=en_US.UTF-8 threads=4
> WSGIProcessGroup testserver_proc
> WSGIApplicationGroup testserver_app
> WSGIScriptAlias /test /usr/lib/test/test.py
> process-group=testserver_proc
>
> …which is actually picked up, according to the Apache log:
>
> src/server/mod_wsgi.c(10229): mod_wsgi (pid=1353502): Setting lang to
> en_US.UTF-8 for daemon process group testserver_proc.
> src/server/mod_wsgi.c(10242): mod_wsgi (pid=1353502): Setting locale to
> en_US.UTF-8 for daemon process group testserver_proc.
> mod_wsgi (pid=1353502): Initializing Python.
> mod_wsgi (pid=1353504): Initializing Python.
> mod_wsgi (pid=1353503): Initializing Python.
> mod_wsgi (pid=1353503): Attach interpreter ''.
> mod_wsgi (pid=1353504): Attach interpreter ''.
> mod_wsgi (pid=1353502): Attach interpreter ''.
> src/server/mod_wsgi.c(9115): mod_wsgi (pid=1353502): Started thread 0 in
> daemon process 'testserver_proc'.
> src/server/mod_wsgi.c(9115): mod_wsgi (pid=1353502): Started thread 1 in
> daemon process 'testserver_proc'.
> src/server/mod_wsgi.c(9115): mod_wsgi (pid=1353502): Started thread 2 in
> daemon process 'testserver_proc'.
> src/server/mod_wsgi.c(9115): mod_wsgi (pid=1353502): Started thread 3 in
> daemon process 'testserver_proc'.
> mod_wsgi (pid=1353502): Create interpreter 'testserver_app'.
> [remote 172.16.96.65:47970] mod_wsgi (pid=1353502, process='testserver_proc',
> application='testserver_app'): Loading Python script file
> '/usr/lib/test/test.py'.
>
> …but the script output reported by curl still is
>
> WSGI: value of 'X_TEST': 0xc3 0x83 0xc2 0xa4
>
> Any idea?
>
> Thanks, Albrecht.
>
> --
> 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 view this discussion on the web visit
> https://groups.google.com/d/msgid/modwsgi/6ca07f28-b050-4e76-b6c1-040ef014c5d7n%40googlegroups.com
>
> <https://groups.google.com/d/msgid/modwsgi/6ca07f28-b050-4e76-b6c1-040ef014c5d7n%40googlegroups.com?utm_medium=email&utm_source=footer>.
--
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 view this discussion on the web visit
https://groups.google.com/d/msgid/modwsgi/15D4953B-A3D5-4A74-AEDB-81908F40F800%40gmail.com.