You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在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占用,导致权限访问被拒绝。

IIS端口绑定配置

内容的提问来源于stack exchange,提问作者Juan Stoppa

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.24 07:53:22