0

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

4

2 回答 2

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 上使用应用程序服务。

于 2019-02-28T22:37:39.520 回答
0

我知道这已经很老了,但是我实际上可以在我的 django 应用程序上通过一个糟糕的工作来解决这个问题。如果你真的进入 wfastcgi 文件,你可以在那里添加环境变量,你的应用程序就可以工作了。不确定这有多糟糕(除了明显的维护问题),但它在 Windows Server 2016、iis 10 和 python 3.7 上对我来说运行良好。

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

于 2019-09-13T16:50:54.823 回答