TypeError: Cannot Unpack Non-Iterable NoneType
TypeError: cannot unpack non-iterable NoneType objectQuick Answer
You are trying to unpack a None value into multiple variables. This happens when a function returns None but you expect it to return a tuple. Fix the function to return values on all code paths.
Why This Happens
Tuple unpacking like a, b = func() requires the right side to be iterable. If func() returns None, Python cannot unpack it. This commonly occurs with functions that forget to include a return statement on all code paths.
The Problem
def get_name_and_age(user):
if user:
return user['name'], user['age']
name, age = get_name_and_age(None)The Fix
def get_name_and_age(user):
if user:
return user['name'], user['age']
return None, None
name, age = get_name_and_age(None)Step-by-Step Fix
- 1
Check the function return
Make sure the function always returns a tuple, even in error cases.
- 2
Handle all code paths
Add explicit return statements for every branch.
- 3
Guard the unpacking
Check the result before unpacking: result = func(); if result: a, b = result.
Bugsly catches this automatically
Bugsly's AI analyzes this error pattern in real-time, explains what went wrong in plain English, and suggests the exact fix — before your users even report it.
Try Bugsly free