MyPingO / FlaskProgressBarTutorial

https://youtu.be/bUfUKtJqaxQ
7 stars 4 forks source link

RuntimeError with Async Views in Flask 3.0.2 and Flask-SocketIO Despite Attempted Fixes #1

Open Erick-Bryan-Cubas opened 8 months ago

Erick-Bryan-Cubas commented 8 months ago

Issue Description

I am encountering a RuntimeError when attempting to use async views with Flask 3.0.2 and Flask-SocketIO. The application is designed to serve web content with Flask and utilize Flask-SocketIO for WebSocket communication. I have followed the recommended practices for async support in Flask and Flask-SocketIO, including ensuring all related packages are up to date. However, the issue persists, preventing the use of async routes.

Environment

Error Output

Traceback (most recent call last):
  File "c:\Users\user\AppData\Local\Programs\Python\Python312\Lib\site-packages\flask\app.py", line 1466, in wsgi_app
    response = self.handle_exception(e)
  ...
  File "c:\Users\user\AppData\Local\Programs\Python\Python312\Lib\site-packages\flask\app.py", line 950, in async_to_sync
    raise RuntimeError(
RuntimeError: Install Flask with the 'async' extra in order to use async views.

Steps to Reproduce

  1. Create a Flask app with an async view function.
  2. Implement Flask-SocketIO for WebSocket communication.
  3. Run the application and access the route triggering the async view.

Expected Behavior

The application should handle the async route without any errors, leveraging Flask’s support for async views.

Actual Behavior

A RuntimeError is thrown, stating the need to install Flask with the 'async' extra, even though the current Flask version (3.0.2) should support async operations natively.

Attempts to Resolve

Despite these efforts, the problem remains unresolved. I am seeking guidance on how to properly configure Flask and Flask-SocketIO for async views or if there is a known issue with the current versions that might be causing this problem.

Thank you for your support.

MyPingO commented 8 months ago

Was the GPT essay really necessary 😂?

To clear up any misunderstanding, Flask does not natively support async. You need to install Flask[async] for it to work. If you already made your project with Flask installed, it could be that Flask[async] isn't being detected.

You can try to pip uninstall Flask and then try installing it again with the async extra and see if that works.

You can look at this SO Thread, there's a bunch of solutions.