The “valueerror: too many values to unpack (expected 2)” error occurs when you do not unpack all the items in a list. This error is often caused by trying to iterate over the items in a dictionary. To solve this problem, use the items() method to iterate over a dictionary.
What does it mean too many values to unpack?
The Python error “too many values to unpack” occurs when you try to extract a number of values from a data structure into variables that don't match the number of values. For example, if you try to unpack the elements of a list into variables whose number doesn't match the number of elements in the list.
How do I stop too many values to unpack in python?
Avoid "Too many values to unpack" in the future
But in the future, consider writing functions that returns the same amount of data in the same type to avoid getting errors. For example, one can simply write a function that returns a list of two elements in some case and three elements in others.