将Flask应用程序部署到Windows Azure并收到wfastcgi错误

时间:2019-02-28 18:14:37

标签: python azure iis flask wfastcgi

我一直在尝试使用App服务将网站部署到Azure。我已经使用了requirements.txt文件来安装flask和wfastcgi以及其他所需的依赖项,我也正在使用Python 3.6。我已经设置了web.config文件以正确启动python并利用wfastcgi包。当我尝试导航到该网站时,出现类似wfastcgi的错误。

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

我的文件存储在“ D:\ home \ site \ wwwroot”中 它的结构就像这样

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

我的FlaskTest.py只是简单的快速入门Flask应用程序。

from flask import Flask
app = Flask(__name__)

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

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

这是我的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>

我真的不确定WSGI_HANDLER密钥出了什么问题。从我已阅读的所有内容来看,这应该可行。我尝试将 init .py添加到目录中,但仍然收到错误消息。出于某种原因,我可以理解Wfastcgi在导入“ app”对象时遇到了麻烦,因为这就是我命名为Flask的对象的原因。对此,任何可以阐明的想法都将不胜感激,因为我已经为此努力了好几天。

2 个答案:

答案 0 :(得分:0)

从评论中复制。

Microsoft已弃用Windows上的Azure App Service上的Python(以及诸如wfastcgi之类的基础组件),

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

因此,当今托管Python应用程序的唯一可行方法是在Linux上使用App Service。

答案 1 :(得分:0)

我知道这已经很老了,但是我确实能够在我的django应用程序上解决这一难题。如果按字面意义进入wfastcgi文件,则可以在其中添加环境变量,然后您的应用程序将运行。不知道这有多严重(除了明显的维护问题),但它在Windows Server 2016,IIS 10和python 3.7上对我来说运行正常。

好的-对此的更新... 如果您在IIS上使用FASTCGI模块。您可以在该特定scriptProcessor的设置上添加环境变量,这样就可以毫无问题地拉动它们。