Search code examples
pythonflaskflask-restful

Internal Server Error when Attempting to Run Quickstart Tutorial for flask_restful


I am attempting to run the tutorial from the Flask RESTful documentation but am running into an error when running the Resourceful routing code. I have copied the code for it verbatim, but when I attempt to run the code, I run into the situation below:

export FLASK_APP=api.py
flask run
curl http://localhost:5000/todo1 -d "data=Remember the milk" -X PUT

And the return is:

{"message": "Internal Server Error"}

Does anyone have a suggestion for what's happening here? Any insight would be appreciated.


Solution

  • When using the flask run command, production mode is the default setting. If Flask encounters an error while running in production mode, it will automatically suppress any errors and only return a generic {"message": "Internal Server Error"}. However, for development this can be very annoying as it makes it difficult to determine the root cause of an error.

    Flask has a built-in development mode that--among other things--will disable this. Since you are using the flask cli the easiest thing to do would be to set an environment variable.

    # Mac/Linux
    $ export FLASK_ENV=development
    
    # Windows
    $ set FLASK_ENV=development
    
    # The same command is used to undo this on both platforms
    $ unset FLASK_ENV
    

    This won't automatically fix the bug you're experiencing, but what it will do is allow you to see why you are encountering the error, which is usually more important anyway.

    You can read more about the other available options for development mode here