Git Product home page Git Product logo

Comments (9)

stealthrabbi avatar stealthrabbi commented on May 18, 2024 1

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.

stealthrabbi avatar stealthrabbi commented on May 18, 2024

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.

nsidnev avatar nsidnev commented on May 18, 2024

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:

  1. skip parts with exporting variables
  2. create .env file in your text editor and fill it with your own DB_CONNECTION and SECRET_KEY variables. I'm not sure about this, but maybe just using postgres://postgres:postgres@localhost:5432/postgres for DB_CONNECTION will work on windows since ports are exported in docker-compose.yml
  3. run docker-compose up to start the app and postgres in docker. Alternatively, you can run docker-compose up -d db to start only postgres in docker and run alembic and uvicorn commands from cmd 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.

stealthrabbi avatar stealthrabbi commented on May 18, 2024

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.

stealthrabbi avatar stealthrabbi commented on May 18, 2024

I can get to the swagger page at http://127.0.0.1:8000/docs however

from fastapi-realworld-example-app.

stealthrabbi avatar stealthrabbi commented on May 18, 2024

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.

nsidnev avatar nsidnev commented on May 18, 2024

{"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.

stealthrabbi avatar stealthrabbi commented on May 18, 2024

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.

nsidnev avatar nsidnev commented on May 18, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.