Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 06:22
    abhinavkulkarni commented #5086
  • 06:21
    abhinavkulkarni commented #5086
  • 06:20
    se7enXF edited #5089
  • 06:16
    se7enXF edited #5089
  • 04:15
    se7enXF opened #5089
  • 04:15
    se7enXF labeled #5089
  • 03:47
    abhinavkulkarni commented #5086
  • 03:46
    abhinavkulkarni commented #5086
  • 03:42
    abhinavkulkarni commented #5086
  • 03:34
    abhinavkulkarni commented #5086
  • 03:27
    abhinavkulkarni commented #5086
  • 03:02
    abhinavkulkarni commented #5086
  • 03:00
    abhinavkulkarni commented #5086
  • Jun 28 20:01
    JarroVGIT commented #5086
  • Jun 28 17:15
    jonatasoli commented #5086
  • Jun 28 17:13
    jonatasoli commented #5086
  • Jun 28 17:11
    jonatasoli commented #5086
  • Jun 28 17:04
    abhinavkulkarni commented #5086
  • Jun 28 16:56
    abhinavkulkarni commented #5086
  • Jun 28 16:31
    zroger commented #3607
akinason
@akinason

Greetings guys, Is there a possibility of adding custom headers from FastAPI swagger doc? I have searched but haven't found anything that works.

I want the frontend dev to pass BusinessId as a header key-pair value. But I do not want to defined a header param on each and every route, rather I have implemented a Depends that works well when tested with Postman and others.

I just need a way to pass this custom header on FastAPI swagger doc as its easier to test from the swagger doc rather than postman.

Thinkal VB
@ThinkalVB
tiangolo/fastapi#5032 I am getting value error when making uploading multiple files optional.
@app.post("/ticket/create/message", tags=["Message component"])
def create_message(ticket_id: int, files: Optional[List[UploadFile]] = File(None), token=Depends(oauth2_scheme)):
richerry
@richerry
OK, my issue was my bad. I was confused since my regular enum strings were the same as the values while the multi-select ones weren't. If I understand right, enums in my front-end consumer of my FastAPI API will use a user-facing description and the value the API wants. The API uses a value it receives from the front-end and the value that is stored in the database. So my issue becomes: how do I add descriptions to enum options in swagger? Or is this something that would just have to be captured in the description of the enum?
Joseph Anderson
@devlancer412

Hi. every body
I'm going to learn fastapi and started yesterday.
But I have some error form very simple project.
There is only one file:main.py

main.py

from fastapi import FastAPI

app = FastAPI()

@app.get("/")
async def root():
return {"message": "Hello World"}

I tried in my console. uvicorn main:app --reload

but such error appeared.
Error loading ASGI app. Could not import module "main".

1 reply
Please give me a hand.
Rami Awar
@RamiAwar
Is it possible to stream JSON data (dictionaries being read from a DB through a generator) and then read it in as dictionaries (similar to readlines) in python using a python client interacting with a FastAPI app?
B-Souty
@B-Souty
Hi everyone, I started my very first serious python project and I chose to use fastapi for that. I have a User models and 3 schemas as described in the doc (UserBase, UserCreate and User). If I want to scope out what data a particular user can access about another user, do I need to create as many schemas as scopes (e.g. anonymous, self, other user, super user, admin, ...) or do I need to write some code to only return the appropriate data based on a requester "role".
2 replies
Prashant Srivastav
@iamprashant

Hi Guys, I am trying to override the parameterized dependency for test. but not sure how I can achieve it.

def get_me(parameter: str):
    def connector_dependency(request: Request):
          doing_something(parameter)
    return connector_dependency

Used like this

Depends(get_me("change_me"))

in test
app.dependency_overrides[get_me] = get_me_test

Chittaranjan Jena
@chitta2_gitlab
Hey Guys I have deployed FastAPI in docker and configured reverse proxy using NGINX
The APIs are secured and is working when i interface with ngrok
But through NGINX the authenticated APIS are not able to read the JWT TOKEN passed through header
Can someone help here please?
ayr-ton
@ayr-ton:one.ems.host
[m]
@chitta2_gitlab: Are you using proxy_pass_request_headers on; in your reverse proxy configuration?
Samuel Valdes Gutierrez
@BigSamu

So regarding a post before, I succesfully been able to implement fastapi-socketio in a project that is modularized in different folders (routes, core, crud, database, models, etc).

The headache I was having was that in one of the routes files I implemented I was having a circular import error. Needed to import the app instance so I can call the socketio instance to emit a message inside the route.py file.

The work around was to do the imports inside the route method (receive_records() method - see below), but thinking this is not an elegant solution. Is there any other way to implement this properly (@tiangolo would appreciate your suggestions)

I set up the socketio instance in the main.py as follows:

# app.py
from fastapi import FastAPI
from fastapi_socketio import SocketManager

app = FastAPI()
socket_manager = SocketManager(app=app)

And in my route.py file I call the socketio instance for emitting an action as follows:

#route.py
@router.post("")
async def receive_record():
     from app.main import app 
     await app.sio.emit('received_record', 'new record received')
Chittaranjan Jena
@chitta2_gitlab
@ayr-ton:one.ems.host i will verify this but it worked when we changed our code to token=req.headers['authorization'], it worked
previously we used to read token=req.headers['jwt_token']
Bjoern
@jesusch
nihau
I have the following setup:
api-gateway with multiple fastapi instances
each one mounted via
FastAPI(root_path='/fooapi')
while I'd like to share a single, cross-api oauth2 redirect-url
FastAPI(root_path='/fooapi', swagger_ui_oauth2_redirect_url='/docs/oauth2-redirect') <- "only" creates an API-relative link (/fooapi/docs/..)
FastAPI(root_path='/fooapi', swagger_ui_oauth2_redirect_url=None, swagger_ui_parameters={'oauth2RedirectUrl': '/docs/oauth2-redirect'}) <- would be missing the mandatory window.location.origin +
Bjoern
@jesusch
any other way making the redirect_url domain absolut (beside providing my own /docs endpoint)?
hichhiker
@hichhiker:matrix.org
[m]
silly question - is there a FastAPI way to generate client lib? I know there are codegens to make libs from OpenAPI/Swagger files - but have not had much luck with those, so curious if there is a better way
hjaltist
@hjaltist
I'm using fastapi in my Company and we use SSO for authentication for it and therefore we have some huge headers.
And I get this error a lot:
WARNING: Invalid HTTP request received.
Traceback (most recent call last):
File "/usr/local/lib/python3.7/site-packages/uvicorn/protocols/http/h11_impl.py", line 136, in handle_events
event = self.conn.next_event()
File "/usr/local/lib/python3.7/site-packages/h11/_connection.py", line 433, in next_event
"Receive buffer too long", error_status_hint=431
h11._util.RemoteProtocolError: Receive buffer too long
is there a way to increase h11's _max_incomplete_event_size?
Marcelo Trylesinski
@Kludex
Yes, just released the new uvicorn
0.18.1
Alexandre Santos
@alexsantos
@Kludex despite uvicorn being now on 0.18.1 that branch that was going to add server logging not being sent to stderr was not merged to 0.18?
Marcelo Trylesinski
@Kludex
Idk what you're talking about
(it's more like a question... what is the branch you're talking about?)
Alexandre Santos
@alexsantos
I can't find it anymore... but I'm pretty sure that it solved some questions about the INFO messages that uvicorn logs on startup wouldn't go to stderr but to a new "uvicorn.server" instead of "uvicorn.error"
Marcelo Trylesinski
@Kludex
2 replies
Samuel MARLHENS
@smarlhens

Hi there :wave: ,

I'm sorry if the subject has already been discussed, I'm discovering Python and fastapi and I'm trying to do the following:

class FooBar(BaseModel):
    item_id: int
    q: list[str] | None = Query(None)


@router.get("/items/{item_id}")
def read_item(params: FooBar = Depends()) -> dict[str, str | int | None | list[str]]:
    print(params) # q is None
    return {"item_id": params.item_id, "q": params.q}

and whe I'm trying to check q is always None using http://0.0.0.0:8000/v1/items/1?q=foo or http://0.0.0.0:8000/v1/items/1?q=foo&q=bar

Is it expected ? Is there any way to get a list of str using Depends ?

Thanks in advance

Thinkal VB
@ThinkalVB
await web_socket.close(code=3005)
When I catch the event on client side i am getting 1006 as the event.code
Is it some bug related with the WebSocket that comes with FastAPI
Marcelo Trylesinski
@Kludex
Maybe related to uvicorn
Do you have a gist I can check later?
Alexandre Santos
@alexsantos
I just created a new FastAPI project and I can't log anything unless I use "print"... seems like I'm back to System.out.println.... The only thing that gets logged are errors but they are not formatted.
from fastapi.logger import logger

from fastapi import FastAPI

app = FastAPI()


@app.get("/")
async def root():
    logger.error("TEST")
    return {"message": "Hello World"}


@app.get("/hello/{name}")
async def say_hello(name: str):
    return {"message": f"Hello {name}"}
5 replies
image.png
Marcelo Trylesinski
@Kludex
you need to add a handler
the fastapi logger is not meant to be used on the application, jfyk
Marcelo Trylesinski
@Kludex
sorry, I broke the logs
if you're running on the latest uvicorn, try to downgrade to 0.17.6
B-Souty
@B-Souty
Hey all, following the fastapi doc , crud operations are located in a separate crud.py file. At the same time, I could accomplish those crud operations using methods on my sqlalchemy models (e.g. update a field, append a child record, do some validation, etc). What is the best practice and why? What is the advantage of using a dedicated crud file rather than using models methods.
B-Souty
@B-Souty
And similarly I can have methods on my pydantic schemas for example to compute the age of a user based on a date_of_birth field. should I have this method on my schema, my model or should I have a function completely separated somewhere else?
3 replies
mdm aswanth
@mdm.aswanth:matrix.org
[m]
anyone please help me with easyauth,how do i get set_db i pacing to easyauth. do i have create a seperate db connection for my client
Alex Hutton
@alex-hutton
Using SQLModel, has anyone created a field that is persisted as jsonb in postgres, which is an array of pydantic models?
Evans
@Johnnyevans32
hi guys, I'm available for projects or roles to work on