What determines which encoding mod_wsgi uses when it reads WSGI scripts: Apache's configured locale (which for me is en_us.UTF8), or something else? (I ask about this because mod_wsgi appears to do low-level manual hackery when reading wsgi script files instead of going through importlib or runpy, which means that it can't handle a zipapp or even something that uses a PEP 263 magic comment to convey encoding information, the latter making it impossible to "wrap" a zipapp with a loader shim even unless something else gives.)
Minimized example (works when you run it using python3 breaks.py, breaks with the errors below if you try to load it using `mod_wsgi-express start-server breaks.py` using a mod_wsgi-express installed into a venv with pip install), note that you will have to save breaks.py as latin1/iso-8859-1 to cause this to break): $ cat breaks.py # coding: latin1 import sys from wsgiref.simple_server import make_server def application(environ, start_response): start_response('200 OK', [('Content-Type', 'text/plain')]) message = 'It works!\n' version = 'Python v' + sys.version.split()[0] + '\n' response = '\n'.join([message, version]) return [response.encode()] def main(): with make_server('', 8100, application) as httpd: httpd.serve_forever() blow_up_unicode = 'â(¡' # \xe2\x28\xa1 if __name__ == '__main__': main() Errors it generates when run under mod_wsgi-express: [Thu Mar 21 20:12:56.942439 2024] [wsgi:error] [pid 3288289:tid 140356515776384] mod_wsgi (pid=3288289): Failed to exec Python script file '/tmp/mod_wsgi-localh ost:8000:1000/handler.wsgi'. [Thu Mar 21 20:12:56.942486 2024] [wsgi:error] [pid 3288289:tid 140356515776384] mod_wsgi (pid=3288289): Exception occurred processing WSGI script '/tmp/mod_wsg i-localhost:8000:1000/handler.wsgi'. [Thu Mar 21 20:12:56.943223 2024] [wsgi:error] [pid 3288289:tid 140356515776384] Traceback (most recent call last): [Thu Mar 21 20:12:56.943329 2024] [wsgi:error] [pid 3288289:tid 140356515776384] File "/tmp/mod_wsgi-localhost:8000:1000/handler.wsgi", line 90, in <module> [Thu Mar 21 20:12:56.943335 2024] [wsgi:error] [pid 3288289:tid 140356515776384] handler = mod_wsgi.server.ApplicationHandler(entry_point, [Thu Mar 21 20:12:56.943337 2024] [wsgi:error] [pid 3288289:tid 140356515776384] ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ [Thu Mar 21 20:12:56.943345 2024] [wsgi:error] [pid 3288289:tid 140356515776384] File "/home/lucas/wsgizip/lib/python3.11/site-packages/mod_wsgi/server/__init__.py", line 1475, in __init__ [Thu Mar 21 20:12:56.943348 2024] [wsgi:error] [pid 3288289:tid 140356515776384] code = compile(fp.read(), entry_point, 'exec', [Thu Mar 21 20:12:56.943350 2024] [wsgi:error] [pid 3288289:tid 140356515776384] ^^^^^^^^^ [Thu Mar 21 20:12:56.943356 2024] [wsgi:error] [pid 3288289:tid 140356515776384] File "<frozen codecs>", line 322, in decode [Thu Mar 21 20:12:56.943371 2024] [wsgi:error] [pid 3288289:tid 140356515776384] UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe2 in position 458: invalid continuation byte -- 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 modwsgi+unsubscr...@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/modwsgi/18b16e2e-4e3c-49f7-84af-7351e4619687n%40googlegroups.com.