In my app, I want to apply access to a given endpoint based on a role, which is an enum. The way it all works is that a logged in (authorized) user, wants to get access to some resources, or create a new user etc…, then his jwt token is decoded, so we can see his roles (enum). I’m going
Tag: fastapi
FASTAPI Delete Operation giving Internal server error
I have this code for delete operation on a Postgresql DB: The create and read operations work fine. If I pass an existing or a non-exsiting id to delete, I get a 500 Internal Server error. The row does get deleted from the table though. If I comment this line deleted_post = cursor.fetchone(), it works okay. Here is the error
FastAPI – Unable to get auth token from middleware’s Request object
Following Starlette documentation (FastAPI uses Starlette for middlewares), response.headers[“Authorization”] should allow me to get the bearer token, but I get a KeyError saying no such attribute exists. When I print response.headers, I get MutableHeaders({‘content-length’: ’14’, ‘content-type’: ‘application/json’}). Why is the authorization attribute not in the header despite of making a request with an auth header? Answer You are trying to
Unexpected indentation when return in python
when I try to return but I got an error in 2nd return signup_result & return login_result https://github.com/microsoft/pyright/blob/main/docs/configuration.md#reportUndefinedVariable here is utils.py I also try to tab 2 times to avoid indentation error in return signup_result & return login_result but still got the same error Unexpected indentationPylance Answer The cognito_login() function contains only one line of code return login_result because that
How can I effectively use the same orm model in two git repositories?
The initial situation is that I have two fast-api servers that access the same database. One is the real service for my application and the other is a service for loading data from different sources. Both services have their own Github repository, but use the same orm data model. My question is: What are best practices to manage this orm
What’s the difference between FastAPI background tasks and Celery tasks?
Recently I read something about this and the point was that celery is more productive. Now, I can’t find detailed information about the difference between these two and what should be the best way to use them. Answer Straight from the documentation: If you need to perform heavy background computation and you don’t necessarily need it to be run by
ValueError:Reshape your data either using array.reshape(-1, 1)if your data has a single feature or array.reshape(1, -1) if it contains a single sample
**the code predict the house price with polynomial regression model and fastapi **` make class have an one parameter and have a 4 value #The train_plynomial_model is a function that takes the Features and returns polynomial model The predict is a function that predict the house price “ I tried to put this sentencenewfeature=newfeature.reshape(-1, 1) Answer You should change features
How to get route’s name using FastAPI/Starlette?
How can I get the name of a route/endpoint using FastAPI/Starlette? I have access to the Request object and I need this information in one of my middlewares. For example, if I hit services/1, I should then be able to get the abc name. Is this possible in FastAPI? Update 1: Output of request.scope Update 2: Providing middleware code where
Fastapi app: empty array or TypeError: Boolean value of this clause is not defined
So, Im doing simple todo-api app with fastapi and sqlmodel. Migrations went fine, but if I run my server, I dont see anything except empy array. I added some data in db file with DB Browser for SQLite, so it isn’t empty. And when I run my server and go to “/”, I see only empty array and no data,
FastAPI does not replace “+” plus symbol in GET request
I understand this is not a FastAPI issue, but how to avoid this using FastAPI? For example: Issuing the following request: returns: Answer The plus sign (+) has a semantic meaning in the query string, i.e., representing the space character. Similarly, the ampersand sign (&), which is used to separate the various key=value pairs in the query string. When a