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

244
Views
¿Es posible usar Flask RestX con la espera asincrónica 2.0+ de Flask?

El uso de async/await se presentó en Flask 2.0. ( https://flask.palletsprojects.com/en/2.0.x/async-await/ )

Estoy usando Flask-RestX, ¿es posible usar async / await en los controladores de solicitudes de RestX?

Algo como:

 @api.route('/try-async') class MyResource(Resource): @api.expect(some_schema) async def get(self): result = await async_function() return result

no funciona y cuando trato de llegar a este punto final aparece el error:

TypeError: Object of type coroutine is not JSON serializable

¿Hay alguna información sobre eso?

Versiones del paquete:

 flask==2.0.1 flask-restx==0.4.0

y también instalé flask[async] como sugiere la documentación.

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

He solucionado esto usando una redirección interna

 @api.route('/try-async') class MyResource(Resource): @api.expect(some_schema) def get(self): return redirect(url_for('.hidden_async'), code=307) @api.route('/hidden-async', methods=['GET']) async def hidden_async(): result = await async_function() return result

Redirigir con code=307 garantizará que cualquier método y cuerpo no cambien después de la redirección ( Enlace ). Por lo tanto, también es posible pasar datos a la función asíncrona.

 @api.route('/try-async') class MyResource(Resource): @api.expect(some_schema) def post(self): return redirect(url_for('.hidden_async'), code=307) @api.route('/hidden-async', methods=['POST']) async def hidden_async(): data = request.get_json() tasks = [async_function(d) for d in data] result = await asyncio.gather(tasks) return result
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!