[Python] Question about behavior in Flask (Python)

Discussão em 'Python' iniciado por Stack, Setembro 17, 2025.

  1. Stack

    Stack Membro Participativo

    I have a question that came up while I was practicing with Flask.

    from flask import Flask, request

    app = Flask(__name__) #Flask instance

    @app.route('/api')
    def api():
    url_data = request.args
    #return type(url_data)
    return url_data

    if __name__ == '__main__':
    app.run(debug=True, port=5001)


    What happens is that when I make a request with curl, (although the error is not due to this tool at all): curl -X POST http://127.0.0.1:5001/api?username=mrobot&password=robot.txt, I get the following TypeError: The view function for 'api' did not return a valid response. The function either returned None or ended without a return statement, 500.

    I tried with type(user_data), because I was looking at what type of data it is (although the official documentation says it is an ImmutableMultiDict), however I would like to know why this error occurs, if it is a dictionary type it is assumed that I could access its elements either in general or through its indexes, am I correct?

    Continue reading...

Compartilhe esta Página