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
- Check the function definition and count how many parameters it expects
- Pass the missing argument: my_func(arg1, arg2) instead of my_func(arg1)
- If the argument is optional in practice, give it a default value: def func(a, b=None):
- 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.
