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
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
FASTAPI SQLAlchemy Creating a table during run time based on user input
The user will be providing some information such as table_x with column_x. And I’d like to create these tables in an existing database or a new database based on the user’s value. These values will be provided during run-time therefore I cannot create the Model beforehand. If anyone could provide some help, let me know! Answer I’ve managed to figure
Python and FastAPI: keep getting 405 when posting response
I have made at fasstapi at https://lectio-fastapi.herokuapp.com/docs#/ When I test on the fastapi site it works like a charm. But when I try to access it from another python program i get 405 when posting the output I am getting is: And I am expecting to get these returns: It seems like to me I need to define something more
How to stream DataFrame using FastAPI without saving the data to csv file?
I would like to know how to stream a DataFrame using FastAPI without having to save the DataFrame to a csv file on disk. Currently, what I managed to do is to stream data from the csv file, but the speed was not very fast compared to returning a FileResponse. The /option7 below is what I’m trying to do. My