IIS上的Python flask应用程序无法在Windows Server 2019上运行

问题描述

问题

我有一个用python编写的简单烧瓶应用程序,我想在Windows Server 2019计算机上使用IIS托管。

该应用已使用Flask随附的开发服务器在本地运行。此外,完全相同的代码可以在我的window-server 2016机器和Windows7工作站上完美运行。

令人沮丧的是,它发出错误500-当我尝试在Windows Server 2019计算机上的IIS下运行它时,“ FastCGI意外退出”。我尝试了各种各样的事情,但是一无所获。我希望有人能帮忙!

设计

该应用是此Microsoft页面上描述的wfastcgi方法的实现: https://docs.microsoft.com/en-us/visualstudio/python/configure-web-apps-for-iis-windows?view=vs-2019

Python脚本是

app_hello.py

from flask import Flask
app = Flask(__name__)

@app.route('/')
def hello_world():
    return ' Hello,world!!!'

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

web.config文件为

web.config

<?xml version="1.0" encoding="utf-8"?>
<configuration>
<system.webServer>
<handlers>
<add name="Python FastCGI" path="*" verb="*" modules="FastCgiModule" scriptProcessor="c:\devel\a_anomaly_detection\.venv\scripts\python.exe|c:\devel\a_anomaly_detection\.venv\lib\site-packages\wfastcgi.py" resourceType="Unspecified" requireAccess="Script" />
</handlers>
        <tracing>
            <traceFailedRequests>
                <add path="*">
                    <traceAreas>
                        <add provider="WWW Server" areas="Authentication,Security,Filter,StaticFile,CGI,Compression,Cache,RequestNotifications,Module,FastCGI,WebSocket" verbosity="Verbose" />
                    </traceAreas>
                    <failureDefinitions timeTaken="00:00:00" statusCodes="500" />
                </add>
            </traceFailedRequests>
        </tracing>
</system.webServer>
<appSettings>
<!-- Required settings -->
<add key="WSGI_HANDLER" value="app_hello.app" />
<add key="PYTHONPATH" value="c:\devel\a_anomaly_detection\website" />
<add key="WSGI_LOG" value="c:\devel\a_anomaly_detection\data\logs\wfastcgi.log" />
</appSettings>
</configuration>

我的软件版本为

  • Windows Server 2019

  • IIS 10

  • python 3.7.6rc1

  • wfastcgi 3.0.0

  • 烧瓶1.1.2

错误500页

[error_500_screen] [1]

tracefailedRequests

我启用了 tracefailedRequests ,这就是报告的内容

  1. NOTIFY_MODULE_START ModuleName =“ FastCgiModule”,Notification =“ EXECUTE_REQUEST_HANDLER”,fIsPostNotification =“ false” 09:08:17.333

  2. FASTCGI_ASSIGN_PROCESS CommandLine =“ c:\ devel \ a_anomaly_detection.venv \ scripts \ python.exe c:\ devel \ a_anomaly_detection.venv \ lib \ site-packages \ wfastcgi.py”,IsNewProcess =“ true”, ProcessId =“ 3708”,RequestNumber =“ 1” 09:08:17.333

  3. FASTCGI_START 09:08:17.333

  4. FASTCGI_WAITING_FOR_RESPONSE 09:08:17.333

  5. FASTCGI_UNEXPECTED_EXIT错误 09:08:17.349

  6. SET_RESPONSE_ERROR_DESCRIPTION 警告 ErrorDescription =“ c:\ devel \ a_anomaly_detection.venv \ scripts \ python.exe-FastCGI进程意外退出” 09:08:17.349

  7. MODULE_SET_RESPONSE_ERROR_STATUS 警告 ModuleName =“ FastCgiModule”,Notification =“ EXECUTE_REQUEST_HANDLER”,HttpStatus =“ 500”,HttpReason =“内部服务器错误”,HttpSubStatus =“ 0”,ErrorCode =“无法再次设置信号量。 (0x67)“,ConfigExceptionInfo =”“ 09:08:17.349

  8. NOTIFY_MODULE_END ModuleName =“ FastCgiModule”,Notification =“ EXECUTE_REQUEST_HANDLER”,fIsPostNotificationEvent =“ false”,NotificationStatus =“ NOTIFICATION_FINISH_REQUEST” 09:08:17.349

解决方法

您很可能已忘记为虚拟环境在服务器Python上安装。查看return !true 文件,并检查文件夹中是否确实有Python,该文件夹指定为 home 参数。

要进行故障排除,请从 c:\ devel \ a_anomaly_detection \ website 文件夹运行以下命令: false并检查其输出

相关问答

依赖报错 idea导入项目后依赖报错,解决方案:https://blog....
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下...
错误1:gradle项目控制台输出为乱码 # 解决方案:https://bl...
错误还原:在查询的过程中,传入的workType为0时,该条件不起...
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct...