I am having some trouble hosting a Flask web service onto Windows Server through IIS. I have followed the tutorial found here:
And have used the resource here to better understand the wfastcgi module: https://pypi.python.org/pypi/wfastcgi
And while I've gotten the tutorial flask app to work as outlined in the tutorial, when I try to host my own Flask app, I get an odd error. I should mention my flask app works perfectly through cmd prompt.
It seems that when the wfastcgi.py module runs, it doesn't recognize the call to a Handler constructor. Here is the error I am getting:
Traceback (most recent call last):
File "C:\web_services\guest_reg_api\wfastcgi.py", line 847, in main
result = handler(record.params, response.start)
TypeError: 'module' object is not callable
In the past, I've had these errors because Windows can't find a Python module, but adding the module's location to my Path system Variables usually solves the issue.
I've verified that all references to Python, Flask, and wfastcgi.py are in my path system variables
I can successfully host an http site through IIS on the same server.
Here is my web.config file:
<?xml version="1.0" encoding="UTF-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="Flask" path="*" verb="*" modules="FastCgiModule" scriptProcessor="C:\Python27\python.exe|C:\web_services\guest_reg_api\wfastcgi.py" resourceType="Unspecified" requireAccess="Script" />
<add name="python-wfastcgi" path="*" verb="*" modules="FastCgiModule" scriptProcessor="C:\Python27\python.exe|C:\Python27\Lib\site-packages\wfastcgi.pyc" resourceType="File" />
</handlers>
</system.webServer>
<appSettings>
<!-- Required settings -->
<add key="WSGI_HANDLER" value="guestreg_api_v2.app" />
<add key="PYTHONPATH" value="C:\web_services\guest_reg_api" />
</appSettings>
</configuration>
I feel like the issue is one of a few things:
I'm not sure how to proceed, outside of trying to deploy the service through apache. I'd prefer this method, though, as I feel like I'm very close to fixing this.
Thanks
Through davidism's comments on my post, I was able to make the necessary change to my web service and get it hosted through IIS.
The problem is that I was following the linked tutorial word for word, and not appreciating what the value for WSGI_HANDLER in the config file meant. I needed to make a call to the Flask instance that I created within my Python script:
Excerpt from my Python script:
from flask import *
...
guestreg_api = Flask(__name__)
Change made to web.config file:
<add key="WSGI_HANDLER" value="guestreg_api_v2.guestreg_api" />