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

168
Views
422 Entidad no procesable en fastapi al devolver la respuesta

Estoy usando una API rápida para hacer inferencias de aprendizaje automático y devolver la respuesta. Hay dos tareas que son controladas por task_id . Para task_id=0 , tanto el solvent como el solute son necesarios para devolver la respuesta cuando se usa task_id=1 . Solo necesito solute . Pero al dar los valores para las claves, se requiere dar un valor solvent en task_id=1 donde no lo necesito. Si no se me da el valor, 422 Unprocessable Entity no procesable. ¿Es su forma de escribir para que no arroje el error si no se proporciona un valor solvente al usar task_id=1

 @app.get('/predict') async def predict(task_id:int, background_tasks: BackgroundTasks,solute,solvent): global task_id_global task_id_global = task_id if task_id == 0: background_tasks.add_task(predictions,solute,solvent) return {'success'} elif task_id == 1: # solvent = None background_tasks.add_task(predictions_two,solute) return {'success'} else: return "Give proper task_id"
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Declare su parámetro como Optional . Por ejemplo:

 from typing import Optional ... async def predict(solvent: Optional[str] = None): ...
over 4 years ago · Santiago Trujillo Report
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!