full-stack-fastapi-template
full-stack-fastapi-template copied to clipboard
Cannot Log in?
Hi,
I followed the wiki page to install:
pip install cookiecutter cookiecutter https://github.com/tiangolo/full-stack-fastapi-postgresql
And then set first_superuser
and first_superuser_password
(this step I just created my own secret key and password without using the generator as suggested by wiki, does it matter?).
But when I open http://localhost/login, and enter the user name and password, it keeps saying 'Incorrect email or password'.
I checked the frontend log in my container:
172.19.0.6 - - [07/Aug/2020:06:40:29 +0000] "GET /login HTTP/1.1" 304 0 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 Safari/537.36" "172.19.0.1"
172.19.0.6 - - [07/Aug/2020:06:40:29 +0000] "GET /service-worker.js HTTP/1.1" 304 0 "http://localhost/login" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 Safari/537.36" "172.19.0.1"
172.19.0.6 - - [07/Aug/2020:06:40:29 +0000] "GET /img/icons/android-chrome-192x192.png HTTP/1.1" 304 0 "http://localhost/login" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 Safari/537.36" "172.19.0.1"
172.19.0.6 - - [07/Aug/2020:06:40:31 +0000] "GET /service-worker.js HTTP/1.1" 304 0 "http://localhost/service-worker.js" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 Safari/537.36" "172.19.0.1"
172.19.0.6 - - [07/Aug/2020:06:40:31 +0000] "GET /precache-manifest.c37eea1a941046fa837fbb856740aa22.js HTTP/1.1" 304 0 "http://localhost/service-worker.js" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 Safari/537.36" "172.19.0.1"
172.19.0.6 - - [07/Aug/2020:06:40:49 +0000] "POST /api/v1/login/access-token HTTP/1.1" 404 556 "http://localhost/login" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/84.0.4147.89 Safari/537.36" "172.19.0.1"
I don't see anything obvious.
Idea?
Does first_superuser
have to be an email address?
I set pgadmin_default_user
to the same username, and I can log onto pgadmin tho.
I also noticed that there was another ticket last year for similar issue.
I have tried to access http://localhost/docs (as suggested by the ticket), but an "404" error is returned.
And the ticket seems to suggest that I should have backend/.env
but it doesn't exist.
And I noticed that there is no container for the backend?
$ sudo docker container ls
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
0d321b949356 dpage/pgadmin4 "/entrypoint.sh" 4 minutes ago Up 3 minutes 80/tcp, 443/tcp, 0.0.0.0:5050->5050/tcp whitequeen_pgadmin_1
25050127ada8 mher/flower "flower --broker=amq…" 4 minutes ago Up 3 minutes 0.0.0.0:5555->5555/tcp whitequeen_flower_1
d7ed26bf41ba postgres:12 "docker-entrypoint.s…" 4 minutes ago Up 3 minutes 5432/tcp whitequeen_db_1
6b35cf6fee0b frontend:latest "nginx -g 'daemon of…" 4 days ago Up 3 minutes 80/tcp whitequeen_frontend_1
cda08343db76 rabbitmq:3 "docker-entrypoint.s…" 4 days ago Up 3 minutes 4369/tcp, 5671-5672/tcp, 25672/tcp whitequeen_queue_1
7b96dd3dcb5d traefik:v2.2 "/entrypoint.sh --pr…" 4 days ago Up 3 minutes 0.0.0.0:80->80/tcp, 0.0.0.0:8090->8080/tcp whitequeen_proxy_1
Is it normal?
same problem here
Does first_superuser have to be an email address? yes. I think it is a source of your issue. BTW - don't forget to remove all containers and volumes related to DB before rebuilding to actually change to new. Good luck
Does first_superuser have to be an email address? yes. I think it is a source of your issue. BTW - don't forget to remove all containers and volumes related to DB before rebuilding to actually change to new. Good luck
I don't have any container running at the moment.
It seems like FastAPI fullstack package just created one volume called [project name]_app-db-data?
$ sudo docker volume ls
DRIVER VOLUME NAME
local 5db6c8c42230d6892643286ef3d61fc4f28c55bb8ff8b9543b355ffea9d2796c
local 89df075ad9e1e8e870943eb21484fc882a79cafacb4f416478834b03e418fd26
local cac365b3a936b96bc2671d28e3e7c75921d66edd12c1e89f97779c462c55c65a
local ddc7df9f2430bdc4baad691d79be2cea16750464224e13d6cebaed4c2ae6da14
local whitequeen_app-db-data
Maybe you should clean up volumes and reinstall app
Use docker volume prune
(https://docs.docker.com/engine/reference/commandline/volume_prune/)
I did
docker volume prune
then retry docker-compose up -d
The problem is my both backend and celeryworker fail to run, so I checked my logs
backend_1 | Checking for script in /app/prestart.sh
backend_1 | Running script /app/prestart.sh
backend_1 | Traceback (most recent call last):
backend_1 | File "/app/app/backend_pre_start.py", line 5, in <module>
backend_1 | from app.db.session import SessionLocal
backend_1 | File "/app/app/db/session.py", line 4, in <module>
backend_1 | from app.core.config import settings
backend_1 | File "/app/app/core/config.py", line 89, in <module>
backend_1 | settings = Settings()
backend_1 | File "pydantic/env_settings.py", line 33, in pydantic.env_settings.BaseSettings.__init__
backend_1 | File "pydantic/main.py", line 346, in pydantic.main.BaseModel.__init__
backend_1 | pydantic.error_wrappers.ValidationError: 2 validation errors for Settings
backend_1 | BACKEND_CORS_ORIGINS -> 0
backend_1 | invalid or missing URL scheme (type=value_error.url.scheme)
backend_1 | FIRST_SUPERUSER
backend_1 | value is not a valid email address (type=value_error.email)
backend_1 | Checking for script in /app/prestart.sh
backend_1 | Running script /app/prestart.sh
backend_1 | Traceback (most recent call last):
backend_1 | File "/app/app/backend_pre_start.py", line 5, in <module>
backend_1 | from app.db.session import SessionLocal
backend_1 | File "/app/app/db/session.py", line 4, in <module>
backend_1 | from app.core.config import settings
backend_1 | File "/app/app/core/config.py", line 89, in <module>
backend_1 | settings = Settings()
backend_1 | File "pydantic/env_settings.py", line 33, in pydantic.env_settings.BaseSettings.__init__
backend_1 | File "pydantic/main.py", line 346, in pydantic.main.BaseModel.__init__
backend_1 | pydantic.error_wrappers.ValidationError: 2 validation errors for Settings
backend_1 | BACKEND_CORS_ORIGINS -> 0
backend_1 | invalid or missing URL scheme (type=value_error.url.scheme)
backend_1 | FIRST_SUPERUSER
backend_1 | value is not a valid email address (type=value_error.email)
backend_1 | Checking for script in /app/prestart.sh
backend_1 | Running script /app/prestart.sh
backend_1 | Traceback (most recent call last):
backend_1 | File "/app/app/backend_pre_start.py", line 5, in <module>
backend_1 | from app.db.session import SessionLocal
backend_1 | File "/app/app/db/session.py", line 4, in <module>
backend_1 | from app.core.config import settings
backend_1 | File "/app/app/core/config.py", line 89, in <module>
backend_1 | settings = Settings()
backend_1 | File "pydantic/env_settings.py", line 33, in pydantic.env_settings.BaseSettings.__init__
backend_1 | File "pydantic/main.py", line 346, in pydantic.main.BaseModel.__init__
backend_1 | pydantic.error_wrappers.ValidationError: 2 validation errors for Settings
backend_1 | BACKEND_CORS_ORIGINS -> 0
backend_1 | invalid or missing URL scheme (type=value_error.url.scheme)
backend_1 | FIRST_SUPERUSER
backend_1 | value is not a valid email address (type=value_error.email)
From logs, I trace where is backend_pre_start.py
locate, but I can't find this file
Here is my trace stack
First
- I did look at backend.dockerfile first Second
- tiangolo/uvicorn-gunicorn-fastapi Third
- tiangolo/uvicorn-gunicorn-docker
@5SMNOONMS5 how did you reinstall? The log seems to complain BACKEND_CORS_ORIGINS
and FIRST_SUPERUSER
are not valid.
I have a similar issue, all containers are running:
I can access the frontend, pgAdmin, dashboard and flower. However, the login is not working and is returning a 404 response. The same is true for
/docs
.
Has anyone an idea what the problem is or how to locate it?
I've deployed the app using jenkins. Here is my Jenkinsfile which is inspired by the .gitlab-ci.yml
file:
pipeline {
agent any
stages {
stage("Prepare") {
steps {
sh """
python3.8 -m venv venv
. venv/bin/activate
pip install docker-auto-labels
"""
echo 'Pulling... ' + env.GIT_BRANCH
}
}
stage("Build") {
stages {
stage("Build Stage") {
when {
expression { env.GIT_BRANCH == 'origin/dev' }
}
steps {
sh """
. venv/bin/activate
TAG=stag FRONTEND_ENV=staging sh ./scripts/build-push.sh
"""
}
}
stage("Build Prod") {
when {
expression { env.GIT_BRANCH == 'origin/main' }
}
steps {
sh """
. venv/bin/activate
TAG=prod FRONTEND_ENV=production sh ./scripts/build-push.sh
"""
}
}
}
}
stage("Deploy") {
stages {
stage("Build Stage") {
when {
expression { env.GIT_BRANCH == 'origin/dev' }
}
steps {
sh """
. venv/bin/activate
DOMAIN=stag.leadxtend.de TRAEFIK_TAG=stag.leadxtend.de STACK_NAME=stag-leadxtend-de TAG=stag sh ./scripts/deploy.sh
"""
}
}
stage("Build Prod") {
when {
expression { env.GIT_BRANCH == 'origin/main' }
}
steps {
sh """
. venv/bin/activate
DOMAIN=leadxtend.de TRAEFIK_TAG=leadxtend.de STACK_NAME=leadxtend-de TAG=prod sh ./scripts/deploy.sh
"""
}
}
}
}
}
}
The deployment of the backend seems to work at least to some point as the pgAdmin shows my initial user and correct tables:
Did you add in backend/app/app/core/config.py
FIRST_SUPERUSER: EmailStr = os.environ.get("FIRST_SUPERUSER", "[email protected]")
FIRST_SUPERUSER_PASSWORD: str = os.environ.get("FIRST_SUPERUSER_PASSWORD", "test-password")
?
I ran into this issue when my first_superuser wasn't formatted as an email. I updated the .env
file and added @app.com
to the FIRST_SUPERUSER
variable and restarted the containers. The next time I logged in I was successful.
@msmith93 Thank you! I was questioning my sanity before that point :D! Definitely worked for me