Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 #231

Open
jstoppa opened this issue May 15, 2024 · 0 comments

Comments

@jstoppa
Copy link

jstoppa commented May 15, 2024

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

@jstoppa jstoppa changed the title Getting permission Error [WinError 10013] An attempt was made to access a socket in a way forbidden by its access permissions when running in with FastAPI 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 May 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant