我一直在尝试使用应用服务将网站部署到 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 对象命名为的原因。任何可以对此有所了解的信息都将不胜感激,因为我这几天一直在抨击它。