Skip to content
Advertisement

Tag: fastapi

Secured endpoints in FastApi using enum

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

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

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

Advertisement