配置:
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>
我总是得到:
出了什么问题?
我没有使用FastCGI,因为该项目没有维护。
此错误是由于缺乏权限或物理路径与虚拟目录的路径不匹配引起的。例如,Web应用物理根路径下不存在Web.config。
验证 Web.config 路径是否存在并且设置了正确的权限。 收集 Process Monitor 日志以获取有关错误的更多信息。
更多信息您可以参考此链接:HRESULT code 0x80070003.