Flask TypeError after updating to Python 3.10

I am using Dash on top of Flask and after upgrading to Python 3.10 I get the following TypeError when loading the main app in my browser:

Traceback (most recent call last):
  File "[PATH_TO_VIRTUALENV]/lib/python3.10/site-packages/flask/app.py", line 2213, in __call__
    return self.wsgi_app(environ, start_response)
  File "[PATH_TO_VIRTUALENV]/lib/python3.10/site-packages/flask/app.py", line 2193, in wsgi_app
    response = self.handle_exception(e)
  File "[PATH_TO_VIRTUALENV]/lib/python3.10/site-packages/flask/app.py", line 2190, in wsgi_app
    response = self.full_dispatch_request()
  File "[PATH_TO_VIRTUALENV]/lib/python3.10/site-packages/flask/app.py", line 1487, in full_dispatch_request
    return self.finalize_request(rv)
  File "[PATH_TO_VIRTUALENV]/lib/python3.10/site-packages/flask/app.py", line 1506, in finalize_request
    response = self.make_response(rv)
  File "[PATH_TO_VIRTUALENV]/lib/python3.10/site-packages/flask/app.py", line 1837, in make_response
    raise TypeError(
TypeError: The view function did not return a valid response. The return type must be a string, dict, list, tuple with headers or status, Response instance, or WSGI callable, but it was a Dash.

I realise this error is typically raised when a Flask route returns data of the wrong type, but as you can see in the traceback the error is not raised from one of my routes or callbacks. All steps in the traceback point to the flask module. A simplified version of my app looks roughly like this. Any pointers?

app.py

from flask import Flask
from subfolder.main import register_module


app = Flask(__name__)
app = register_module(app)

if __name__ == "__main__":
    flask.run(debug=True, port=8000)

subfolder/main.py

def register_module(flask: Flask) -> Flask:
    dash = Dash(
        __name__,
        server=flask,
    )

    # Dash logic lives here, a few callbacks and routes
    
    return flask

Hello @distracted_husky,

Welcome to the community!

What version of Dash did you install when updating? This could be a versioning issue with Flask and up until Dash 2.10, there was no control to make sure the installing for Flask was compatible.

Thanks for the quick reply!

I have tried several versions of Dash, and am currently on 2.11.1.

For Flask, flask --version returns

Python 3.10.6
Flask 2.2.5
Werkzeug 2.2.3

Uninstall flask and werkzueg and then reinstall Dash.

1 Like

That seems to have done the trick, thanks!

1 Like