2

I am working on Fast API project based on Angular UI. Before wheel package converted it is been working fine. So now when I convert the application into .whl package using below command:

python3.9 setup.py bdist_wheel

wheel file get converted also it run the UI server on http://127.0.0.1:8000/ successfully but it does not call api endpoints and throws error "INFO: 127.0.0.1:54394 - "POST /api/devices/connect HTTP/1.1" 405 Method Not Allowed" enter image description here

Content of files main.py is as below:

app = FastAPI(
    title="ProjectName",
    description="ProjectName Description",
)

app.add_middleware(
    CORSMiddleware,
    allow_origins=["*"],
    allow_credentials=True,
    allow_methods=["*"],
    allow_headers=["*"],
)

static_dir = os.path.join(os.path.dirname(__file__), "static")
app.mount("/", StaticFiles(directory=static_dir, html=True), name="static")

@app.post("/api/devices/connect")
async def auth(auth_input: AuthInput):
    print('API called here.....')
    ## other codes goes here
    
    
def start_server():
    print("Starting Server...Success")
    webbrowser.open("http://127.0.0.1:8000/")
    uvicorn.run(
        "projectname.main:app",
        host="0.0.0.0",
        port=8000,
        log_level="debug",
        reload=True,
    )

I run the python wheel file as below:

pip install --extra-index-url projectName.whl

Also I tried running the API on http://127.0.0.1:8000/docs but it throws same error 405 method not allowed.

How can I run this API, its a POST method. And running this api on http://127.0.0.1:8000/docs gives me attached error:

enter image description here

Rakesh Shetty
  • 4,548
  • 7
  • 40
  • 79

0 Answers0