ProjectStack
python

TypeError: missing required positional argument

You called a function but didn't pass all the arguments it requires. Python functions must receive all non-optional parameters — every parameter without a default value must be provided.

Common causes

  • Calling a function with fewer arguments than it defines
  • Forgetting to pass self when calling a method incorrectly
  • Adding a new required parameter to a function but not updating all the call sites
  • Confusing a method call with a function call and missing the instance as the first argument

How to fix it

  1. Check the function definition and count how many parameters it expects
  2. Pass the missing argument: my_func(arg1, arg2) instead of my_func(arg1)
  3. If the argument is optional in practice, give it a default value: def func(a, b=None):
  4. For class methods, make sure you're calling them on an instance: obj.method() not MyClass.method()

Example

Traceback (most recent call last): File "app.py", line 8, in <module> result = add(5) TypeError: add() missing 1 required positional argument: 'b'

Calling add(5) when the function is defined as def add(a, b):

Have a different error?

Paste any error message into the Error Translator to get an instant explanation.