Search code examples
python-3.xwindowsapache2mod-wsgiwsgi

Why does my .wsgi file give me Internal Server Error?


Apache 2.4 - RHEL 8.3 (Ootpa) - Windows

I have problems running the WSGI file on the server. Getting Internal Server Error. (I'm new at this)

I have installed the "python3-mod_wsgi" (as the mod_wsgi is said to not work with windows)

Checking if working:

root@xxx# sudo httpd -M | grep wsgi
proxy_uwsgi_module (shared)
wsgi_module (shared)

Which means it works(?)

I tested with the hello world (test_wsgi.py script) example:

def application(environ, start_response): status = '200 OK' output = 'Hello World!'
response_headers = [('Content-type', 'text/plain'),
                    ('Content-Length', str(len(output)))]
start_response(status, response_headers)

return [output]

Which worked:

Image of hello world in browser

My conf file: (edited out the /path/)

<VirtualHost *:80>
        ServerAdmin webmaster@localhost
        ServerName my.server.name
        DocumentRoot /path/api

        WSGIScriptAlias /lisens/test_wsgi /path/api/lisens/test_wsgi.py

        WSGIScriptAlias /lisens/hello_world /path/api/lisens/hello_world.wsgi

        <Directory/path/lisens>
                AllowOverride All
                Require all granted
        </Directory>

        Alias /static /path/lisensAPI/static>
        <Directory /path/lisens/lisensAPI/static/>
                AllowOverride All
                Require all granted
        </Directory>

        LogLevel info

</VirtualHost>

But when I try out the hello_world.wsgi:

def application(environ, start_response):
    status = '200 OK'
    output = 'Hello World!\n'
    response_headers = [('Content-type', 'text/plain'),
                        ('Content-Length', str(len(output)))]
    start_response(status, response_headers)
    return [output]

I get Internal Server Error

I'm doing this test to later apply to my Flask application.

Any ideas? Please tell me if there is more information required to solve this.


Solution

  • Found the log. Apparently the string was wrong. added b'' in front.

    Answer found here: TypeError: sequence of byte string values expected, value of type str found