Replies: 3 comments 1 reply
-
same here 🙋 |
Beta Was this translation helpful? Give feedback.
-
Hey @spacecaps-cao ! I decided to use a GET request to circumvent this error and pass in an ID field in the URL that corresponds to the "body" of the request which I'm getting from the database. Essentially, the frontend makes a POST request to the DB on the "body" data and then calls the GET request in the server and passes in the ID field in the URL. The backend server will then retrieve the data details from the database. |
Beta Was this translation helpful? Give feedback.
-
I think In FastAPI, when you're about to pass a parameter as a from typing import Annotated
from pydantic import BaseModel
from fastapi import Body
class DemoDocument(BaseModel):
query: str
history: list
@router.post("/path/to/your/endpoint", tags=["some tag"])
async def example(document: Annotated[Document, Body]):
pass or simply this: from typing import Annotated
from pydantic import BaseModel
from fastapi import Body
@router.post("/path/to/your/endpoint", tags=["some tag"])
async def example(document: Document = Body()):
pass And one more thing, it's recommended to include a db connection into path operation by way of from typing import Annotated
from sqlalchemy.orm import Session
from fastapi import Depends
@router.get("/path/to/your/endpoint")
def example(db: Annotated[Session, Depends(get_db)]):
pass
def get_db():
db = db_session()
try:
yield db
finally:
db.close() |
Beta Was this translation helpful? Give feedback.
-
First Check
Commit to Help
Example Code
Description
I'm getting a
msg | "Input should be a valid dictionary or object to extract fields from"
error on the frontend side even though I've confirmed that I'm passing inquery
andhistory
in the request payload:{"query":"random query","history":[]}
I'm also getting this error on the frontend:
Error: Expected content-type to be text/event-stream, Actual: application/json
I'm only getting these on the POST request but when I use a GET request, it works fine, however, this means I can't add in a
body
which is what I'm looking to do with@microsoft/fetch-event-source
in the frontend:I'd like to add that everything works fine in the POST endpoint when making it through the swagger
/docs
Operating System
Linux
Operating System Details
No response
FastAPI Version
0.103.0
Pydantic Version
2.3.0
Python Version
Python 3.9.17
Additional Context
No response
Beta Was this translation helpful? Give feedback.
All reactions