question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Specifying a port does not work, always a random port is assigned.

See original GitHub issue

First 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:closed
  • Created a year ago
  • Comments:7 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
Blue9commented, Sep 27, 2022

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.

1reaction
Kludexcommented, Sep 27, 2022

INFO: Uvicorn running on http://127.0.0.1:8000/ (Press CTRL+C to quit)

Server ☝️

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

Client ☝️

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found