
This error happens when you use tuple unpacking (assigning multiple variables at once) but the number of variables on the left doesn’t match the number of items on the right. In Python, this is known as a ValueError not enough values to unpack issue.
The Cause (Not Enough Values)
my_list = [1]
a, b = my_list # CRASH!
# Error: ValueError: not enough values to unpack (expected 2, got 1)Python tries to put my_list[0] into a, but there’s nothing left over to put into b.
The Cause (Too Many Values)
You can also get the opposite error:
my_list = [1, 2, 3]
a, b = my_list # CRASH!
# Error: ValueError: too many values to unpack (expected 2)Common Scenario: Dictionary Loops
This is the #1 place beginners see this. They forget that .items() returns two things (key and value).
Problem Code:
my_dict = {"name": "Alice", "age": 25}
for key in my_dict.items(): # .items() returns [('name', 'Alice'), ('age', 25)]
print(key)
# Output: ('name', 'Alice')
# ('age', 25)Problem Code 2:
for key in my_dict: # Just looping a dict gives keys
a, b = key # CRASH! ValueError (trying to unpack 'name')The Fix: Always unpack .items() into two variables.
for key, value in my_dict.items():
print(f"{key} = {value}")

![3D illustration of a file path blocked by illegal characters causing an OSError [Errno 22] Invalid Argument in Python.](https://pythonprohub.com/wp-content/uploads/2026/01/fix-oserror-errno-22-invalid-argument-file-paths-768x429.png)


