pgjones / hypercorn

Hypercorn is an ASGI and WSGI Server based on Hyper libraries and inspired by Gunicorn.

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Getting permission Error [WinError 10013] An attempt was made to access a socket in a way forbidden by its access permissions when running FastAPI in IIS

jstoppa opened this issue · comments

I have an issue that appears to be related to hypercorn as this does not happen with uvicorn

I'm trying to setup FastAPI in IIS using hypercorn and I keep getting the error

PermissionError: [WinError 10013] An attempt was made to access a socket in a way forbidden by its access permissions

My web.config is the following

<?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"
            stdoutLogEnabled="true" stdoutLogFile="C:\logs\python.log" startupTimeLimit="120" >
        </httpPlatform>
        <httpErrors errorMode="Detailed" />
    </system.webServer>
</configuration>

If I stop IIS and I run the command below it works fine, it's only when running it inside IIS.

C:\inetpub\wwwroot\FastAPI\Scripts\python.exe -m hypercorn app.main:app

I also tried to grant IIS_IUSRS access to python.exe but it didn't make any difference, it was suggested in this post as when calling the API it hangs forever

I suspect it's something to do with the IIS port binding, if I change the web.config to point at another port (e.g. 8080) different than the binding port in IIS then I'm able to access the API (e.g. by navigating to http://localhost:8080), it feels to me IIS is using the port when hypercorn is trying to use it

More info in here, my current workaround is to use uvicorn https://stackoverflow.com/questions/78471188/fastapi-running-in-iis-getting-permissionerrorwinerror-10013-an-attempt-was?noredirect=1#comment138365253_78471188