python value_error ai_generated true

ValueError: not enough values to unpack (expected 2, got 1)

ID: python/valueerror-not-enough-values

Also available as: JSON · Markdown
95%Fix Rate
95%Confidence
50Evidence
2023-01-01First Seen

Version Compatibility

VersionStatusIntroducedDeprecatedNotes
311 active

Root Cause

Tuple unpacking mismatch. Common in for loops over dicts without .items().

generic

Workarounds

  1. 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

  2. 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 shape

    Sources: https://docs.python.org/3/library/functions.html#print

Dead Ends

Common approaches that don't work:

  1. Add * to catch remaining values 65% fail

    Masks the real issue — wrong data shape

  2. Pad the iterable with None values 60% fail

    Doesn't fix the source of wrong-length data

Error Chain

Frequently confused with: