如何在 IIS 10 上使用 FastAPI 运行 Python?

问题描述 投票:0回答:1

配置:

  • Windows Server 2019
  • https://www.iis.net/downloads/microsoft/httpplatformhandler
  • 安装了 httpPlatformHandler x64
  • 为所有用户在 C:\python312-32\ 中安装了 Python 3.12.1 32 位
  • 使用
  • 安装了FastAPI库
  • 使用自定义帐户(User-A)作为身份创建新的应用程序池(Pool-A),无托管代码,集成管道
  • 为日志创建了 C:\python-logs\ 文件夹
  • 使用文件 main.py 创建了 C:\python-app\
  • 在文件夹中为用户 A 设置完全控制:python312-32、python-logs、python-app
  • 添加了应用程序以使用 Pool-A 路由 /python-app

C:\python-app\main.py:

from fastapi import FastAPI
app = FastAPI()
@app.get("/")
async def read_root():
    return {"message": "Sample app"}

C:\python-app\web.config(基于 https://learn.microsoft.com/en-us/visualstudio/python/configure-web-apps-for-iis-windows?view=vs-2022

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <system.webServer>
    <handlers>
      <add name="PythonHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified"/>
    </handlers>
    <httpPlatform processPath="c:\python312-32\python.exe"
                  arguments="c:\python-app\main.py --port %HTTP_PLATFORM_PORT%"
                  stdoutLogEnabled="true"
                  stdoutLogFile="c:\python-app\python.log"
                  startupTimeLimit="60"
                  processesPerApplication="16">
      <environmentVariables>
        <environmentVariable name="SERVER_PORT" value="%HTTP_PLATFORM_PORT%" />
      </environmentVariables>
    </httpPlatform>
  </system.webServer>
</configuration>

我总是得到:

  • HTTP 错误 500.19 - 内部服务器错误
  • 错误代码0x80070003
  • 配置错误无法读取配置文件

出了什么问题?

我没有使用FastCGI,因为该项目没有维护。

python python-3.x iis fastapi iis-10
1个回答
0
投票

此错误是由于缺乏权限或物理路径与虚拟目录的路径不匹配引起的。例如,Web应用物理根路径下不存在Web.config。

验证 Web.config 路径是否存在并且设置了正确的权限。 收集 Process Monitor 日志以获取有关错误的更多信息。

更多信息您可以参考此链接:HRESULT code 0x80070003.

© www.soinside.com 2019 - 2024. All rights reserved.