2

I am having trouble with getting uvicorn to start. I am very new to python and fastapi so I am assuming I have doing something very silly.

I have isolated the problem to being in my api_router.py file

from fastapi import APIRouter
from API.endpoints import user_endpoints

api_router = APIRouter()

api_router.include_router(user_endpoints, prefix="/user", tags=["User"])

When I comment out from API.endpoints import user_endpoints and api_router.include_router(user_endpoints, prefix="/user", tags=["User"]), the error does not occur. Am I trying to import my user_endpoints.py file incorrectly? I have attached an image of the directory structure.

user_endpoints.py looks like this:

from fastapi.routing import APIRouter
from typing import Optional, List
from API.schema.user import User
from models.user import Users
from main import db

router = APIRouter

@router.get('/users', response_model=List[User], status_code=200)
def get_all_users():
    users=db.query(Users).all()
    return users

@router.get('/users/{user_id}')
def get_user(user_id):
    pass
    
@router.post('/users')
def create_user():
    pass

@router.put('/users/{user_id}')
def update_user(user_id):
    pass

@router.delete('/users/{user_id}')
def delete_user(user_id):
    pass

enter image description here

Any help with this would be greatly appreciated.

Thanks,

Greg

Greg
  • 35
  • 1
  • 2
  • 6
  • 1
    Did you find a solution? Facing the same problem right now. – Timo Jun 17 '22 at 11:55
  • It may not be all SO users who can't see the image but I wish people would post text where possible so it can also be copy pasted. – NeilG Jan 17 '23 at 02:59

1 Answers1

2

I think it's talking about the current working directory of your terminal, when you feed it uvicorn main:app ... not being able to find main. Make your terminal's working directory same as main.py