5

I need to use aioflask for seting webhooks for my telegram-bot. Here my code, where I set webhook:

from aioflask import Flask, request
...

app = Flask(__name__)
...

@app.route('/')
async def webhook():
    await bot.delete_webhook()
    await bot.set_webhook(url=APP_URL)

    return '!', 200
...

But, when I run app, it give me this error:

Traceback (most recent call last):
  File "D:/Python_Projects/FilmMarketBot/check.py", line 1, in <module>
    from aioflask import Flask, request
  File "D:\Python_Projects\FilmMarketBot\venv\lib\site-packages\aioflask\__init__.py", line 2, in <module>
    from .app import Flask
  File "D:\Python_Projects\FilmMarketBot\venv\lib\site-packages\aioflask\app.py", line 14, in <module>
    from .ctx import AppContext, RequestContext
  File "D:\Python_Projects\FilmMarketBot\venv\lib\site-packages\aioflask\ctx.py", line 4, in <module>
    from flask.ctx import AppContext as OriginalAppContext, \
ImportError: cannot import name '_app_ctx_stack' from 'flask.ctx' (D:\Python_Projects\FilmMarketBot\venv\lib\site-packages\flask\ctx.py)

Please, tell how can I fix it. ...Why always me?

CallMeStag
  • 5,467
  • 1
  • 7
  • 22
Tomas Angelo
  • 63
  • 1
  • 6

1 Answers1

3

There seems to be a breaking change in Flask 2.2.0, which causes this incompatibility. As a workaround you can downgrade your Flask package to 2.1.3. This change solved the issue for me.

Reported the issue on GitHub: https://github.com/miguelgrinberg/aioflask/issues/10

Agita
  • 110
  • 2
  • 5
  • I just want to add for anyone that might be confused why it doesn't work for them. check this question out. https://stackoverflow.com/questions/53270646/flask-runs-out-of-virtual-environment I had a global flask installation installed, which overrode my `flask` command. You should be able to see the version with `flask --version` too – Talik Mar 28 '23 at 16:03