1 year ago

#355351

test-img

CrimockLyte

Fatal Python error: init_fs_encoding when running Apache with mod_wsgi to deploy Flask

I am currently attempting to deploy a Flask application using mod_wsgi and Apache. I am using Python 3.10 on a Windows 10 machine and I believe to have configured everything properly. Below is my flask_app.conf:

WSGIPythonHome "C:/../../venv"
<VirtualHost *:80>
    ServerName XX.XX.XX.XX:80
    WSGIScriptAlias / C:/../app/flask_app.wsgi
    <Directory C:/../flask_app>
        Require all granted
    </Directory>
</VirtualHost>

and here is the relevant code added to the Apache httpd.conf file:

ServerName XX.XX.XX.XX:80
LoadFile <primary python3.10 dll>
LoadModule wsgi_module "venv/lib/site-packages/mod_wsgi/server/mod_wsgi.cp310-win_amd64.pyd"
WSGIPythonHome "C:/../venv"

Include conf/flask_app.conf

Strangely it appears that the server functions if I simply run the command

httpd.exe

However, it does stall on the command prompt, as if processing a continuous function. Also, if I try to start Apache2.4 in Windows Services or use the command:

httpd.exe -k start

An error occurs on startup giving the following relevant snippet in the error.log for Apache:

Fatal Python error: init_fs_encoding: failed to get the Python codec of the filesystem encoding
Python runtime state: core initialized
ModuleNotFoundError: No module named 'encodings'

This has been a hard problem to debug and any guidance would be appreciated. Please let me know if any more information would be helpful.

python

apache

flask

wsgi

0 Answers

Your Answer

Accepted video resources