votes up 1

The view function did not return a valid response. The return type must be a string, dict, tuple, Response instance, or WSGI callable, but it was a (type(rv).__name__).

Package:
flask
github stars 56479
Exception Class:
TypeError

Raise code

    raise TypeError(
                        f"{e}\nThe view function did not return a valid"
                        " response. The return type must be a string,"
                        " dict, tuple, Response instance, or WSGI"
                        f" callable, but it was a {type(rv).__name__}."
                    ).with_traceback(sys.exc_info()[2])
            else:
                raise TypeError(
                    "The view function did not return a valid"
                    " response. The return type must be a string,"
                    " dict, tuple, Response instance, or WSGI"
                    f" callable, but it was a {type(rv).__name__}."
                )

        rv = t.cast(Response, rv)
        # prefer
😲 Agile task management is now easier than calling a taxi. #Tracklify
🙏 Scream for help to Ukraine
Today, 2nd July 2022, Russia continues bombing and firing Ukraine. Don't trust Russia, they are bombing us and brazenly lying in same time they are not doing this 😠, civilians and children are dying too! We are screaming and asking exactly you to help us, we want to survive, our families, children, older ones.
Please spread the information, and ask your governemnt to stop Russia by any means. We promise to work extrahard after survival to make the world safer place for all.

Ways to fix

votes up -3 votes down

The exception is thrown when the view function returning a non-valid response.

Reproduce an error

Let's create a simple flask application.

from flask import Flask

app = Flask(__name__)

@app.route('/')
def hello():
  return 531

In the above code, we returning an integer value in the view function but it is not allowed. An acceptable type can be a string, dict, tuple, Response instance, or WSGI callable.

Fix Version

from flask import Flask

app = Flask(__name__)

@app.route('/')
def hello():
  return "Hello World!"
Sep 29, 2021 anonim answer
anonim 13.0k

Add a possible fix

Please authorize to post fix