r/FastAPI • • Feb 05 '25

feedback request Simple boilerplate

Hey there guys, I have been working on a simple boilerplate project that contains user authentication, authorization, role-based access control, and CRUD. It's my first time using Python for web development, and I had issues like modularization, and handling migrations. Check the repo and drop your comments. Thanks in advance

Repo

34 Upvotes

12 comments sorted by

View all comments

2

u/SonGokussj4 Feb 06 '25

Did not work for me sadly. I've installed it with python 3.10, using uv project manager done uv pip install -r requirements.txt - first, requirements.txt has not valid format, it should be something like fastapi>=xx.x.x and not fastapi xx.x.x and then when I start the project i had to update the uvicorn main:app --reload to uvicorn src.main:app --reload but it still failed on

INFO:     Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
INFO:     Started reloader process [21589] using WatchFiles
INFO:     Started server process [21591]
INFO:     Waiting for application startup.
INFO:src.main:Creating database and tables
ERROR:    Traceback (most recent call last):
  File "/home/username/GIT/fast-api-demo/.venv/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 146, in __init__
    self._dbapi_connection = engine.raw_connection()
  File "/home/username/GIT/fast-api-demo/.venv/lib/python3.10/site-packages/sqlalchemy/engine/base.py", line 3298, in raw_connection
    return self.pool.connect()
  ...
  ...
  ...
  File "/home/username/GIT/fast-api-demo/.venv/lib/python3.10/site-packages/psycopg2/__init__.py", line 122, in connect
    conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
psycopg2.OperationalError: connection to server at "localhost" (127.0.0.1), port 5432 failed: Connection refused
        Is the server running on that host and accepting TCP/IP connections?


The above exception was the direct cause of the following exception:

Traceback (most recent call last):
  File "/home/username/GIT/fast-api-demo/.venv/lib/python3.10/site-packages/starlette/routing.py", line 693, in lifespan
    async with self.lifespan_context(app) as maybe_state:
  File "/home/username/.local/share/uv/python/cpython-3.10.8-linux-x86_64-gnu/lib/python3.10/contextlib.py", line 199, in __aenter__
    return await anext(self.gen)
  ...
  ...
  ...
  File "/home/username/GIT/fast-api-demo/.venv/lib/python3.10/site-packages/psycopg2/__init__.py", line 122, in connect
    conn = _connect(dsn, connection_factory=connection_factory, **kwasync)
sqlalchemy.exc.OperationalError: (psycopg2.OperationalError) connection to server at "localhost" (127.0.0.1), port 5432 failed: Connection refused
        Is the server running on that host and accepting TCP/IP connections?

(Background on this error at: https://sqlalche.me/e/20/e3q8)

ERROR:    Application startup failed. Exiting.

1

u/Majestic_Rule9192 Feb 06 '25

I will update the requirements.txt file but the error you are getting is because of the connection string you put in your `.env` file make sure you use `127.0.0.1` instead of `localhost`.