We have some error with mod_wsgi but can't solve.

16 views
Skip to first unread message

Tin Tun Naing

unread,
Nov 3, 2021, 12:52:11 AM11/3/21
to modwsgi
We installed python version 3.6 and apache 2.4 on CentOS 8 and connect with postgresql. 
And then installed mod_wsgi for run python code.
After we make some configuration in /etc/httpd/conf.d/wsgi.conf  as follows -

--------------------------------------------------------------------------------
LoadModule wsgi_module /etc/httpd/modules/mod_wsgi_python3.so
Alias /map /var/www/map/

<Directory /var/www/orikomap/>
Options ExecCGI MultiViews Indexes
MultiViewsMatch Handlers

AddHandler wsgi-script .py
AddHandler wsgi-script .wsgi
DirectoryIndex index.html index.php index.py app.wsgi

Order allow,deny
Allow from all
</Directory>
----------------------------------------------------------------------------------------

And then we add python code to target directory -> /var/www/map/index.py as follow

-------------------------------------------------------------------------------------------
import sys

def application(environ, start_response):
status = '200 OK'
output = u'mod_wsgi.process_group = %s' % repr(environ['mod_wsgi.process_group'])
response_headers = [('Content-type', 'text/plain'),
('Content-Length', str(len(output)))]
start_response(status, response_headers)

return [output.encode('UTF-8')]
----------------------------------------------------------------------------------------

we got follow result -

After we add a new python file on the same directory -> /var/www/map/map.py .


but we can't call another python file as follow.
http//:ipaddress/polygon.py

----------------------------------------------------------------------------------------------
[Fri Oct 29 03:56:35.064042 2021] [wsgi:error] [pid 2840:tid 140610811930368] [client 192.168.1.8:53246] mod_wsgi (pid=2840): Target WSGI script '/var/www/map/polygon.py' does not contain WSGI application 'application'.


So how can we solve this problem, how to run other Python files on the same directory using wsgi.

Thank you.


Graham Dumpleton

unread,
Nov 3, 2021, 12:56:28 AM11/3/21
to mod...@googlegroups.com
Every file would need to have a WSGI application entry point called "application". The error says you don't have one in that file.

Overall this sort of approach of using AddHandler with separate WSGI files in a directory to handle different routes is generally regarded as bad practice these days. Instead of this approach you are much better off using a WSGI framework. A lightweight example of a WSGI framework is Flask. I strongly recommend you go look at Flask and how it works rather than pursuing your current path.


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 modwsgi+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/modwsgi/e33beebb-e3c7-4c0c-a573-21bc1a536b93n%40googlegroups.com.

Reply all
Reply to author
Forward
0 new messages