0

I have been trying to deploy a website to Azure with App services. I have used a requirements.txt file to install flask and wfastcgi and other needed dependencies also I am using Python 3.6. I have setup the web.config file to properly start python and utilize wfastcgi package as well. When i try to navigate to the site i get a wfastcgi error like this.

Error occurred while reading WSGI handler:

Traceback (most recent call last):
File "D:\Python34\Scripts\wfastcgi.py", line 711, in main
env, handler = read_wsgi_handler(response.physical_path)
File "D:\Python34\Scripts\wfastcgi.py", line 568, in read_wsgi_handler
return env, get_wsgi_handler(handler_name)
File "D:\Python34\Scripts\wfastcgi.py", line 551, in get_wsgi_handler
raise ValueError('"%s" could not be imported' % handler_name)
ValueError: "D:\home\site\wwwroot\FlaskTest.app" could not be imported

My files are stored in the "D:\home\site\wwwroot" It is structured like so

D:\home\site\wwwroot |FlaskTest.py |web.config |requirements.txt

My FlaskTest.py is just the simple quickstart Flask app.

from flask import Flask
app = Flask(__name__)

@app.route("/")
def hello():
 return "Hello from FastCGI via IIS!"

if __name__ == '__main__':
    app.run()

And here is my Web.config:

<configuration>
<system.webServer>
<handlers>
   <add name="PythonHandler" path="*" verb="*" modules="FastCgiModule"
    scriptProcessor="D:\Python34\python.exe|D:\Python34\scripts\wfastcgi.py"
    resourceType="Unspecified" requireAccess="Script"/>
</handlers>
<httpErrors errorMode="Detailed" />
</system.webServer>
<appSettings>
 <add key="PYTHONPATH" value="D:\home\site\wwwroot" />
 <add key="WSGI_HANDLER" value="D:\home\site\wwwroot\FlaskTest.app" />
 <add key="WSGI_LOG" value="D:\home\LogFiles\wfastcgi.log"/>
</appSettings>
</configuration>

I'm really not sure what is wrong with the WSGI_HANDLER key. From everything I have read this should work. I have tried adding a init.py to the directory and I still receive the error. For some reason I can understand Wfastcgi is having trouble importing the "app" object as that is what I have the Flask object named as. Any light that can be shed on this would be much appreciated as I have been bashing my head on it for days now.

Sterling Dunn
  • 57
  • 1
  • 7
  • That means you still use the deprecated approach, https://learn.microsoft.com/en-us/visualstudio/python/publishing-python-web-applications-to-azure-from-visual-studio?view=vs-2017 Please use the Linux based App Service instead. – Lex Li Feb 28 '19 at 18:43
  • So am I correct in thinking that using windows env in azure for a flask app just wont work period? There is so much documentation out there and examples of other people doing it though. Did azure just take this functionality away entirely then and are forcing people to do it on linux? – Sterling Dunn Feb 28 '19 at 18:46
  • I believe they made the right choice of not bothering people with complex Python on IIS/Windows setup and the compatibility issues. It is not "forcing people to do it on Linux", because Python is native on Linux. – Lex Li Feb 28 '19 at 18:49
  • Yeah I completely understand as it does make more sense to do it on linux environment, I am just more familiar with windows env and was hoping to go that direction to be able to support it better in the future. – Sterling Dunn Feb 28 '19 at 19:02
  • If you want to post that comment as an answer ill mark it as the correct answer if you would like. – Sterling Dunn Feb 28 '19 at 19:02

2 Answers2

0

Copied from the comment.

Microsoft deprecated Python on Azure App Service on Windows (along with the underlying components such as wfastcgi),

https://learn.microsoft.com/en-us/visualstudio/python/publishing-python-web-applications-to-azure-from-visual-studio?view=vs-2017

Therefore, the only feasible way of hosting Python apps today is to use App Service on Linux.

Lex Li
  • 60,503
  • 9
  • 116
  • 147
0

I know this is super old, but I was able to actually get this working on my django app with a crappy work around. If you literally go into the wfastcgi file, you can add the environment variables there, and your application will work. Not sure how bad this (asides from the obvious maintenance issues) but its been working fine for me on windows server 2016, iis 10 and python 3.7.

Alright - An update to this... If you are using FASTCGI Module on IIS. You can add the environment variables on the settings for that specific scriptProcessor, and it pulls them in no problem.

wdfc
  • 374
  • 4
  • 9