I’ve recently set up apache server to serve my flask app on windows. Let me tell you about my setup.
- I’ve download apache through apache lounge. Have extracted it in C:\Apache24.
- I did install mod_wsgi in a virtual python 3.7.7
- Copied mod_wsgi configuration in the httpd.conf file
- created my_app.conf in the conf directory of Apache
But I’m getting the following error in the error.log file of apache…
[Fri Nov 11 18:44:00.985814 2022] [wsgi:error] [pid 9456:tid 1396] [client 127.0.0.1:58152] mod_wsgi (pid=9456): Exception occurred processing WSGI script 'J:/tools/pipecrew/ashish/workspace/tools/wsgi_scripts/shotgrid_ami_handler.wsgi'. [Fri Nov 11 18:44:00.985814 2022] [wsgi:error] [pid 9456:tid 1396] [client 127.0.0.1:58152] TypeError: 'module' object is not callable\r [Fri Nov 11 18:44:01.020776 2022] [wsgi:error] [pid 9456:tid 1392] [client 127.0.0.1:58153] mod_wsgi (pid=9456): Exception occurred processing WSGI script 'J:/tools/pipecrew/ashish/workspace/tools/wsgi_scripts/shotgrid_ami_handler.wsgi'., referer: http://fpservices.in/boom [Fri Nov 11 18:44:01.020776 2022] [wsgi:error] [pid 9456:tid 1392] [client 127.0.0.1:58153] TypeError: 'module' object is not callable\r, referer: http://fpservices.in/boom
Here are the rest of my snippets
- Apache httpd.conf
LoadFile "J:/tools/rez_packages/python/3.7.7/platform-windows/python37.dll" LoadModule wsgi_module "D:/virtual_python/python-3/mod_wsgi/lib/site-packages/mod_wsgi/server/mod_wsgi.cp37-win_amd64.pyd" WSGIPythonHome "D:/virtual_python/python-3/mod_wsgi" # Include Flask File Include conf/shotgrid_ami_handler.conf
- my flask app conf file in the conf directory of Apache
<VirtualHost *:80> ServerName fpservices.in WSGIScriptAlias / J:/tools/pipecrew/ashish/workspace/tools/wsgi_scripts/shotgrid_ami_handler.wsgi <Directory J:/tools/pipecrew/ashish/workspace/tools/shotgrid_ami_handler> WSGIScriptReloading On Require all granted </Directory> </VirtualHost>
- and my wsgi file…
import sys sys.path.insert(0, 'J:\\tools\\pipecrew\\ashish\\workspace\\tools') from shotgrid_ami_handler import app as application
- and finally my flask app…
from flask import Flask, request, Response app = Flask(__name__) @app.route('/boom', methods=['GET', 'POST']) def boom(): return 'boom!' if __name__ == '__main__': app.run(host='0.0.0.0', port=4576, debug=True)
Can someone please point out why I’m getting ‘module’ object is not callable error here?
I’m trying to execute my flask routing function to execute through my Apache server. But I’m not getting enough error info in the apache error.log file to even try something.
It’s quite a very silly error. In my wsgi script I imported my main flask module as application object instead of the Flask object that’s inside the module. So my flask app has a module
app which contains the Flask object
app. So instead of doing this
from shotgrid_ami_handler import app as application
I should have done this
from shotgrid_ami_handler.app import app as application
Answered By – Vicspidy