在IIS中部署FastAPI遇PermissionError:WinError10013权限问题求助
在IIS中通过Hypercorn部署FastAPI时遇到权限错误
错误详情
运行时持续抛出以下错误:
PermissionError: [WinError 10013] An attempt was made to access a socket in a way forbidden by its access permissions
已执行的操作
- 参考FastAPI社区的IIS部署指引完成配置,当前
web.config内容如下:
<?xml version="1.0" encoding="utf-8"?> <configuration> <system.webServer> <handlers accessPolicy="Read, Execute, Script"> <remove name="httpPlatformHandler"/> <add name="httpPlatformHandler" path="*" verb="*" modules="httpPlatformHandler" resourceType="Unspecified" /> </handlers> <httpPlatform processPath="C:\inetpub\wwwroot\FastAPI\Scripts\python.exe" arguments="-m hypercorn app.main:app --bind 127.0.0.1:8080 --keep-alive 5 --worker-class asyncio --workers 4" stdoutLogEnabled="true" stdoutLogFile="C:\logs\python.log" startupTimeLimit="120" requestTimeout="00:05:00" startupRetryCount="3" processesPerApplication="1"> </httpPlatform> <httpErrors errorMode="Detailed" /> </system.webServer> </configuration>
- 停止IIS后,单独执行以下命令可正常启动服务:
C:\inetpub\wwwroot\FastAPI\Scripts\python.exe -m hypercorn app.main:app --bind 127.0.0.1:8080 --keep-alive 5 --worker-class asyncio --workers 4
- 尝试为
python.exe授予IIS_IUSRS权限,但未解决问题。
问题推测
将web.config中Hypercorn绑定的端口改为IIS绑定端口之外的端口(如8000)时,服务可正常访问(例如通过http://localhost:8000)。因此推测错误原因是:Hypercorn尝试绑定的端口已被IIS占用,导致权限访问被拒绝。

内容的提问来源于stack exchange,提问作者Juan Stoppa
相关产品推荐
相关产品推荐

