unpack error 🐍 Python

ValueError: too many values to unpack (expected 2)

Tuple unpacking got more (or fewer) values than variables on the left.

Seen on: Python

Meaning

Common when iterating a dict without .items(), splitting strings with more separators than expected, or functions returning a different number of values.

Common causes

  • for k, v in dict: (missing .items())
  • line.split(",") returning more parts
  • Function returns a different tuple size

⚡ Quick fix

  1. Use for k, v in d.items()
  2. split with maxsplit: s.split(",", 1)
  3. Use star-unpacking: first, *rest = parts

Detailed fix by platform

Python

  1. key, value = line.split("=", 1)

How to diagnose

  1. Values — Expected vs actual count
  2. Source — What is being unpacked?

🧠 Still stuck? Analyze your error

Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.