ValueError 🐍 Python

ValueError: invalid literal for int() with base 10: 'abc'

int() received a string that isn’t a whole number — empty, decimal, whitespace or text.

Seen on: Python

Meaning

int() only accepts digit strings (optionally signed). "3.5", "", "1,000" and "12a" all fail. The quoted value in the message is exactly what was passed.

Common causes

  • Empty string from input/CSV
  • Decimal string passed to int()
  • Thousands separators or currency symbols
  • Header row parsed as data

⚡ Quick fix

  1. Strip and validate before converting
  2. Use int(float(s)) for decimal strings when truncation is intended
  3. Remove separators: s.replace(',', '')
  4. Catch ValueError and report the bad row

Detailed fix by platform

Python

  1. python
    try: qty = int(row["qty"].strip())
    except ValueError: errors.append(row)

How to diagnose

  1. Value — What string is quoted in the message?
  2. Source — Form, CSV, env var?

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