Comments (9)
Great. That did it. And I also see the JWT_TOKEN_PREFIX
in config.py
that Thank you very much for your patience and responsiveness.
from fastapi-realworld-example-app.
Also, does postgres need to be installed on the local system? That's unclear until you go to run createdb
. Ideally that would be in the readme.
from fastapi-realworld-example-app.
Sorry, but I'm not developing on windows, so I'm not sure about the exact steps to run this project there. So further, only my thoughts, which I didn't check:
- skip parts with exporting variables
- create
.env
file in your text editor and fill it with your ownDB_CONNECTION
andSECRET_KEY
variables. I'm not sure about this, but maybe just usingpostgres://postgres:postgres@localhost:5432/postgres
forDB_CONNECTION
will work on windows since ports are exported indocker-compose.yml
- run
docker-compose up
to start the app and postgres in docker. Alternatively, you can rundocker-compose up -d db
to start only postgres in docker and runalembic
anduvicorn
commands fromcmd
to start the server directly on the system.
In fact, if you have postgres installed locally on your system and it's running, then you can simply skip docker
and connect this app directly to your postgres (just pass correct postgres DSN to DB_CONNECTION
).
from fastapi-realworld-example-app.
So I'd like to just use the postgres docker container and not have it installed locally. I assume I have to do this within a poetry shell, but I ran this and it looks like the app was able to connect to the DB, but when i browse to http://localhost:8000, I don't get anything.
PS C:\Projects\FastApiTests\fastapi-realworld-example-app> alembic upgrade head
INFO [alembic.runtime.migration] Context impl PostgresqlImpl.
INFO [alembic.runtime.migration] Will assume transactional DDL.
PS C:\Projects\FastApiTests\fastapi-realworld-example-app> uvicorn app.main:app --reload
INFO: Uvicorn running on http://127.0.0.1:8000 (Press CTRL+C to quit)
INFO: Started reloader process [15104] using statreload
INFO: Started server process [7216]
2021-06-26 15:55:13.999 | INFO | uvicorn.server:serve:65 - Started server process [7216]
INFO: Waiting for application startup.
2021-06-26 15:55:14.016 | INFO | uvicorn.lifespan.on:startup:45 - Waiting for application startup.
2021-06-26 15:55:14.017 | INFO | app.db.events:connect_to_db:9 - Connecting to DatabaseURL('postgresql://postgres:********@localhost:5432/postgres')
2021-06-26 15:55:14.201 | INFO | app.db.events:connect_to_db:17 - Connection established
INFO: Application startup complete.
2021-06-26 15:55:14.205 | INFO | uvicorn.lifespan.on:startup:59 - Application startup complete.
2021-06-26 15:55:20.017 | INFO | uvicorn.protocols.http.h11_impl:send:440 - 127.0.0.1:13733 - "GET / HTTP/1.1" 404
browser:
{"errors":["Not Found"]}
from fastapi-realworld-example-app.
I can get to the swagger page at http://127.0.0.1:8000/docs however
from fastapi-realworld-example-app.
I'm also not sure what I'm supposed to do be authorized. I didn't see where in the code or in the readme it specifies about creating a user.
from fastapi-realworld-example-app.
{"errors":["Not Found"]}
It's correct. If you open swagger, you will see that all endpoints are placed under /api/
path. This application is backend only, so trying to access non-existent route will result in 404 error.
I'm also not sure what I'm supposed to do be authorized. I didn't see where in the code or in the readme it specifies about creating a user.
Check out the original specification that this project implements. It describes all routes for this application.
from fastapi-realworld-example-app.
Thanks. That makes sense, I forgot on another toy FastAPI proj I was making, I had set up a route at /
that gave a response.
OK, so I look at the spec and noticed that POST /api/users/
was available, so I created a user successfully and got an auth token. But when I click the Authorize button in swagger and provide that token, I still get 403 forbidden on the other API endpoints. I am able to exercise /api/users/login
to log in with email / pass successfully.
The curl command that Swagger creates includes the Authorization token in the header, so I'm not sure what the issue is:
curl -X 'GET' \
'http://127.0.0.1:8000/api/articles/feed?limit=20&offset=0' \
-H 'accept: application/json' \
-H 'Authorization: eyJ0eXAi[redacted]'
from fastapi-realworld-example-app.
The authorization header should include not only the token itself, but also a special string in front of it. Typically the "Bearer"
string is used in the authorization header along with the token, but this project uses "Token"
because it is a specification requirement.
Therefore, if you want to login with swagger, you should pass Token {access_token}
there.
from fastapi-realworld-example-app.
Related Issues (20)
- error views HOT 1
- Use pydantic's BaseSettings for configuration instead of startlette's config HOT 1
- 500 error getting articles HOT 1
- queries.pyi / aiosql HOT 1
- Test will try to use docker, even when told not to.... HOT 4
- how we can apply transaction to this project? HOT 1
- Rationale behind fake FakeAsyncPGPool
- No module named dotenv
- Why not provide requirement.txt file HOT 1
- Contributing HOT 2
- User registration failed "relation "users" does not exist" HOT 3
- Question: Where do you inject Request? HOT 1
- Update test running guide HOT 6
- Add documentation HOT 2
- scalability issue HOT 6
- Possible Deadlock on Connection Pool HOT 2
- There seems to be a bug? HOT 1
- How can I run this app on Google app engine without requirements.txt HOT 2
- Can you talk more about how you split queries between aiosql and pypika? HOT 5
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from fastapi-realworld-example-app.