Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

978
Visualizações
RuntimeError: Install Flask with the 'async' extra in order to use async views

When i try run this locally with docker run (locally) i am getting the error below.. However, i have already run "pip install "flask[async]" and everything seems to be installed.... but same error! Anybody idea whats wrong? Thanks!

from flask import Flask
from flask import request
from flask import Response
import json
import commacount



app = Flask(__name__)

@app.routes('/')
async def home():
    x = str(request.args.get('x'))
    answer = str(commacount.commaCount(x))
    await asyncio.sleep(2)

    
    
    r = {
        "x": x,
        "answer": answer
    }

    reply = json.dumps(r)

    response = Response(response = reply, status=200, mimetype="application/json")
    
    response.headers['Content-Type']='application/json'
    response.headers['Access-Control-Allow-Orgin']='*'

    return response

if __name__ == '__main__':
    loop = asyncio.get_event_loop()
    loop.run_until_complete(app.run(host='0.0.0.0', port=5000))
[2021-12-12 04:42:36,711] ERROR in app: Exception on / [GET]
Traceback (most recent call last):
  File "/usr/local/lib/python3.6/dist-packages/flask/app.py", line 2073, in wsgi_app
    response = self.full_dispatch_request()
  File "/usr/local/lib/python3.6/dist-packages/flask/app.py", line 1518, in full_dispatch_request
    rv = self.handle_user_exception(e)
  File "/usr/local/lib/python3.6/dist-packages/flask/app.py", line 1516, in full_dispatch_request
    rv = self.dispatch_request()
  File "/usr/local/lib/python3.6/dist-packages/flask/app.py", line 1502, in dispatch_request
    return self.ensure_sync(self.view_functions[rule.endpoint])(**req.view_args)
  File "/usr/local/lib/python3.6/dist-packages/flask/app.py", line 1599, in ensure_sync
    return self.async_to_sync(func)
  File "/usr/local/lib/python3.6/dist-packages/flask/app.py", line 1622, in async_to_sync
    ) from None
RuntimeError: Install Flask with the 'async' extra in order to use async views.
172.17.0.1 - - [12/Dec/2021 04:42:36] "GET /?x=,.., HTTP/1.1" 500 -
over 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

First thing you need to use @app.route instead of @app.routes. You also need to install aioflask along with flask to overcome this RuntimeError

Check below simple example -

from flask import Flask

app = Flask(__name__)
app.env = "development"


@app.route('/')
async def home():
    return {"text": "Hello!"}


if __name__ == '__main__':
    app.run(debug=True)
over 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda