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

101
Views
API rápida, acepta una matriz en la solicitud posterior

Estoy tratando de aprender a usar la biblioteca Fast API. Estoy tratando de aceptar una matriz en la publicación usando frozenset como dice la documentación, pero parece que no funciona.

 import logging from fastapi import FastAPI, BackgroundTasks from worker.celery_app import celery_app log = logging.getLogger(__name__) app = FastAPI() def celery_on_message(body): """ Logs the initiation of the endpoint """ log.warn(body) def background_on_message(task): """ logs the function when it is added to queue """ log.warn(task.get(on_message=celery_on_message, propagate=False)) @app.get("/") async def root(stocks: frozenset, background_task: BackgroundTasks): """ :param stocks: stocks to be analyzed :param background_task: initiate the tasks queue :type background_task: starlette.background.BackgroundTasks :return: """ task_name = None # set correct task name based on the way you run the example log.log(level=1, msg=f'{stocks}') task_name = "app.app.worker.celery_worker.compute_stock_indicators" task = celery_app.send_task(task_name, args=[stocks]) background_task.add_task(background_on_message, task) return {"message": "Stocks analyzed"}

Cuando estoy usando los documentos de Swagger para enviar una solicitud:

 curl -X GET "http://127.0.0.1:8000/?stocks=wix&stocks=amzn" -H "accept: application/json"

la respuesta es:

 { "detail": [ { "loc": [ "query", "stocks" ], "msg": "value is not a valid frozenset", "type": "type_error.frozenset" } ] }
over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

creo que hay un pequeño error

Está intentando enviar una solicitud POST pero solo tiene un punto final GET

 @app.post("/")

esto debería solucionar el problema, pero también, al usar Tipo para anotar, use escribir

 from typing import FrozenSet @app.post("/") async def root(stocks: FrozenSet, background_task: BackgroundTasks):

La World Wide Web (W3) también admite la recepción de una solicitud Body in GET , pero también se desaconseja encarecidamente. Consulte la publicación W3 al respecto. OpenAPI incluye la información del cuerpo en la solicitud, y será compatible con OpenAPI en las próximas versiones, pero aún no es compatible con SwaggerUI.

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!