Specifying a port does not work, always a random port is assigned.
See original GitHub issueFirst Check
- I added a very descriptive title to this issue.
- I used the GitHub search to find a similar issue and didn’t find it.
- I searched the FastAPI documentation, with the integrated search.
- I already searched in Google “How to X in FastAPI” and didn’t find any information.
- I already read and followed all the tutorial in the docs and didn’t find an answer.
- I already checked if it is not related to FastAPI but to Pydantic.
- I already checked if it is not related to FastAPI but to Swagger UI.
- I already checked if it is not related to FastAPI but to ReDoc.
Commit to Help
- I commit to help with one of those options 👆
Example Code
from fastapi import FastAPI
app= FastAPI(
redoc_url= None,
)
app.get("/")
async def root():
return ("test")
Description
I am trying to run the code above,
python -m uvicorn main:app --port=8000 --reload
Which runs the API, that part is OK. However, the port is always assigned randomly and I cannot find a way to fix this.
INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit) INFO: Started reloader process [2432] using StatReload INFO: Started server process [2524] INFO: Waiting for application startup. INFO: Application startup complete. INFO: 127.0.0.1:64692 - “GET /docs HTTP/1.1” 200 OK INFO: 127.0.0.1:64692 - “GET /openapi.json HTTP/1.1” 200 OK
Operating System
Windows
Operating System Details
Windows 11 Home SL
FastAPI Version
0.68.0
Python Version
3.10.2
Additional Context
No response
Issue Analytics
- State:
- Created a year ago
- Comments:7 (2 by maintainers)
Top Results From Across the Web
Rancher picks a random port once instead of per-container ...
When provisioning a stack from rancher-compose , Rancher appears to pick one port for a port mapping that isn't fixed (i.e. docker dynamically ......
Read more >Spring Boot - How to get the running port - Stack Overflow
port = 0 in my application.properties so I can have a random port. After the server is booted up and running on a...
Read more >What are dynamic port numbers and how do they work?
Dynamic port numbers enable applications to communicate with each other using TCP or UDP. Learn how dynamic ports work and are standardized.
Read more >How are source ports determined and how can I force it to use ...
Ephemeral ports are temporary ports assigned by a machine's IP stack, and are assigned from a designated range of ports for this purpose....
Read more >The default dynamic port range for TCP/IP has changed in ...
Microsoft customers who deploy servers that are running Windows Server 2008 may have problems that affect RPC communication between servers if ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
As @Kludex mentioned,
127.0.0.1:64692
is the client address, and your server is still running on port 8000. If you’d like to learn more you can read about ephemeral ports.Server ☝️
Client ☝️