Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

202
Views
Solicitud POST de JS a FastAPI obteniendo "422 Entidad no procesable"

Estoy empezando a trabajar en un proyecto con React y FastAPI.

En el lado del servidor:

 from fastapi import APIRouter, Request, Depends, Response, encoders import typing import datetime from app.db.session import get_db from app.db.crud import ( create_lead, ) from app.db.schemas import LeadCreate leads_router = r = APIRouter() @r.post("/leads", response_model=LeadCreate) async def lead_create( # request: Request, lead: LeadCreate, db=Depends(get_db), ): lead.datetime_insert = datetime.datetime.now() return create_lead(db, lead)
 from pydantic import BaseModel import datetime class LeadCreate(BaseModel): email: str source: str datetime_insert: datetime.datetime class Config: orm_mode = True
 from sqlalchemy import Boolean, Column, Integer, String, DateTime from .session import Base class Lead(Base): __tablename__ = "lead" id = Column(Integer, primary_key=True, index=True) email = Column(String) source = Column(String) datetime_insert = Column(DateTime)

En el lado frontal:

 export const create_lead = async (email: string, source: string) => { if (!(email.length > 0)) { throw new Error('Email was not provided'); } const d = {"email": email, "source": source, "datetime_insert": "",} const request = new Request('/api/v1/leads', { method: 'POST', body: JSON.stringify(d), }); const response = await fetch(request); if (response.status === 500) { throw new Error('Internal server error'); } const data = await response.json(); if (response.status > 400 && response.status < 500) { if (data.detail) { throw data.detail; } throw data; } return data; };

Sin embargo, recibo el siguiente error en el registro de back-end: "POST /api/v1/leads HTTP/1.0" 422 Unprocessable Entity

Ya he intentado usar FormData . Creo que está relacionado con la estructura de datos, donde el lado de la interfaz envía algo diferente de lo esperado por el lado del servidor.

ingrese la descripción de la imagen aquí

about 4 years ago · Juan Pablo Isaza
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!