TypeError: Unexpected Keyword Argument

TypeError: foo() got an unexpected keyword argument 'bar'

Quick Answer

You passed a keyword argument the function does not accept. Check the function signature for valid parameter names or add **kwargs to accept arbitrary keywords.

Why This Happens

When calling a function with keyword arguments, Python matches each keyword to a parameter name. If no parameter matches and the function does not accept **kwargs, Python raises this error.

The Problem

def create_user(name, email):
    return {'name': name, 'email': email}

user = create_user(name='Alice', username='alice')

The Fix

def create_user(name, email):
    return {'name': name, 'email': email}

user = create_user(name='Alice', email='alice@example.com')

Step-by-Step Fix

  1. 1

    Check parameter names

    Look at the function definition and verify the keyword argument name matches.

  2. 2

    Check for typos

    A misspelled keyword argument will not match.

  3. 3

    Add **kwargs if needed

    If the function should accept arbitrary keywords, add **kwargs to the signature.

Bugsly catches this automatically

Bugsly's AI analyzes this error pattern in real-time, explains what went wrong in plain English, and suggests the exact fix — before your users even report it.

Try Bugsly free