python
value_error
ai_generated
true
ValueError: not enough values to unpack (expected 2, got 1)
ID: python/valueerror-not-enough-values
95%Fix Rate
95%Confidence
50Evidence
2023-01-01First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 311 | active | — | — | — |
Root Cause
Tuple unpacking mismatch. Common in for loops over dicts without .items().
genericWorkarounds
-
95% success Check if iterating dict — use .items() for key-value pairs
for key, value in my_dict.items(): # not: for k, v in my_dict:
Sources: https://docs.python.org/3/library/stdtypes.html#dict.items
-
90% success Print/inspect the actual data to see its shape, then fix unpacking count
for line in data: parts = line.split(',') print(f'Expected 3 fields, got {len(parts)}: {parts}') # Now fix unpacking count to match actual data shapeSources: https://docs.python.org/3/library/functions.html#print
Dead Ends
Common approaches that don't work:
-
Add * to catch remaining values
65% fail
Masks the real issue — wrong data shape
-
Pad the iterable with None values
60% fail
Doesn't fix the source of wrong-length data
Error Chain
Frequently confused with: