Skip to content

FastAPI VS Code Tutorial missing instructions on customizing port for launching api code #24591

@arbinarybard

Description

@arbinarybard

Does this issue occur when all extensions are disabled?: N/A

  • VS Code Version: 1.94.2
  • OS Version: Windows 11 23H2

Steps to Reproduce:

  1. Follow the instructions to setup FastAPI application: https://code.visualstudio.com/docs/python/tutorial-fastapi
  2. Launch the debugging session using F5 for the python file
  3. If Port 8000 is already used by another program, it throws following error
    ERROR: [WinError 10013] An attempt was made to access a socket in a way forbidden by its access permissions

There is no instruction in this page as to how to resolve this issue. The solution is to create a custom "launch.json" under .vscode folder that allows overriding port for uvicorn module. This resolves the issue while launching python file using F5.

{
    // Use IntelliSense to learn about possible attributes.
    // Hover to view descriptions of existing attributes.
    // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
    "version": "0.2.0",
    "configurations": [
        {
            "name": "Python Debugger: FastAPI",
            "type": "debugpy",
            "request": "launch",
            "module": "uvicorn",
            "args": [
                "groceries-plugin.main:app",
                "--port",  // This option is for overriding port
                "20000", // Custom port number to avoid [WinError 10013] error
                "--reload"
            ],
            "jinja": true
        }
    ]
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    triage-neededNeeds assignment to the proper sub-team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions