shaare.it

TypeError: __init__() got an unexpected keyword argument 'debug'

7 Dec 2025

1 min read

TypeError: unexpected kwarg ‘debug’

$ python app.py
Traceback (most recent call last):
  ...
TypeError: __init__() got an unexpected keyword argument 'debug'

Why this happens

Flask(__name__, debug=True) is invalid—debug is not a constructor kwarg. Debug mode is controlled via app.run(debug=True) or app.config['DEBUG'] = True.

Fix

  • Remove debug from constructor.
  • Use app.run(debug=True) or set config.

Wrong code

from flask import Flask
app = Flask(__name__, debug=True)  # wrong

Fixed code

from flask import Flask
app = Flask(__name__)

if __name__ == "__main__":
    app.run(debug=True)