Python TypeError: missing 1 required positional argument — Causes & Fix
What Does This Error Mean?
Python raises TypeError: <function>() missing 1 required positional argument: '<param>' when you call a function or method without supplying all of its required arguments. The interpreter knows exactly which argument is missing because it's declared in the function signature without a default value.
Common Causes (With Code)
1. Calling a function with fewer arguments than it defines
❌ Causes the error
def greet(name, language):
return f"Hello {name}, you speak {language}"
greet("Alice")
# TypeError: greet() missing 1 required positional argument: 'language'
2. Forgetting self — calling an instance method as a static method
❌ Causes the error
class Dog:
def bark(self):
print("Woof!")
Dog.bark()
# TypeError: Dog.bark() missing 1 required positional argument: 'self'
3. Class __init__ missing required arguments on instantiation
❌ Causes the error
class User:
def __init__(self, username, email):
self.username = username
self.email = email
u = User("alice")
# TypeError: User.__init__() missing 1 required positional argument: 'email'
4. Passing a method reference instead of calling it
❌ Causes the error
def process(data, transformer):
return transformer(data)
def double(x):
return x * 2
# Accidentally passing two ints instead of a callable
process(5, 10)
# TypeError: 'int' object is not callable — related pattern
How to Fix It
Fix 1 — Pass all required arguments
✅ Correct
def greet(name, language):
return f"Hello {name}, you speak {language}"
print(greet("Alice", "Python"))
# Hello Alice, you speak Python
Fix 2 — Add a default value to make the argument optional
✅ Correct
def greet(name, language="English"):
return f"Hello {name}, you speak {language}"
print(greet("Alice")) # Hello Alice, you speak English
print(greet("Bob", "Python")) # Hello Bob, you speak Python
Fix 3 — Call instance methods on an instance, not the class
✅ Correct
class Dog:
def bark(self):
print("Woof!")
rex = Dog() # create an instance
rex.bark() # ✅ Woof!
Fix 4 — Provide all constructor arguments
✅ Correct
class User:
def __init__(self, username, email):
self.username = username
self.email = email
u = User("alice", "alice@example.com") # ✅
print(u.username) # alice
Frequently Asked Questions
What's the difference between a positional argument and a keyword argument?
A positional argument is matched by its position in the call. A keyword argument is matched by name (greet(name="Alice", language="Python")). Both fill required parameters — the difference is how you write the call, not how the function declares them.
How do I make all arguments optional?
Assign a default value to each parameter in the function signature. Parameters with defaults must come after required ones:
def connect(host, port=5432, timeout=30):
...
connect("localhost") # ✅ port=5432, timeout=30
connect("localhost", 3306) # ✅ port=3306, timeout=30