Ask a Question
Ask Question Login
Corporate Training
  1. Community
  2. Salesforce
  3. Question
Salesforce

TypeError cannot unpack non-iterable NoneType object

Asked by Carl Paige Jul 29, 2021 1.9K views 3 answers
Share

About this question

from cv2 import cv2
import numpy as np
import pyzbar.pyzbar as pyzbar
import base64
import time
import datetime
import xlwt 
from xlwt import Workbook
cap = cv2.VideoCapture(0)
font = cv2.FONT_HERSHEY_PLAIN
fob=open('attendence.txt','w+')
names=[]
def enterData(z):
    if z in names:
        pass
    else:
        names.append(z)
        z=''.join(str(z))
        fob.write(z+'n')
    return names
print('Reading...')
def checkData(data):
    try:
        data=str(base64.b64decode(data).decode())
    except(TypeError):
        print('Invalid ID !!!')
        return
    if data in names:
        print('Already Present')
    else:
        print('n'+str(len(names)+1)+'n'+data)
        enterData(data)
    cv2.putText(frame, str(base64.b64decode(obj.data)), (50, 50), font, 2,
                (255, 0, 0), 3)
    
while True:
    _,frame = cap.read()
 
    decodedObjects = pyzbar.decode(frame)
    for obj in decodedObjects:
        checkData(obj.data)
        #print("Data", base64.b64decode(obj.data))
        #enterData(base64.b64decode(obj.data))
        #print(len(names))
        #sys.stdout.write('r'+'Reading...'+str(len(names))+'t'+str(base64.b64decode(obj.data)))
        #sys.stdout.flush()
        time.sleep(1)
       
    cv2.imshow("Frame", frame)
    if cv2.waitKey(1)& 0xFF == ord('s'):
        cv2.destroyAllWindows()
        break
    
fob.close()
d_date = datetime.datetime.now()
reg_format_date = d_date.strftime("%d-%m-%Y %I:%M:%S %p")
reg_format_date=reg_format_date.replace(':',' ')
def writeExcel(names,reg_format_date):
    wb = Workbook()
    
    sheet1 = wb.add_sheet('Sheet 1')
    for i in range(0,len(names)):
        sheet1.write(i, 1, names[i]) 
    wb.save(reg_format_date+'.xls')
writeExcel(names,reg_format_date)


Your answer

3 Answers

Bileha8859 Latest answer

Answered on Jul 9, 2025

The NoneType error usually occurs when the pyzbar.decode() function doesn't find a barcode/QR code color block jam in the frame. You should check decodedObjects before iterating: 

if decodedObjects is not None:  
    for obj in decodedObjects:  
        ...

You can add a condition to check if frame exists before processing:

_, frame = cap.read()  
if frame is None:   

    continue  

Was this helpful?

Johnharper

Answered on Feb 17, 2025

Hello @ slope game, the error message "TypeError: cannot unpack non-iterable NoneType object" typically indicates that a function is trying to return multiple values, but it is returning None instead. In your code, this can happen in a few places, particularly with the cap.read() method or any function that is expected to return a value but is not. I think you shold ensure that all functions that are supposed to return values do so. Specifically, the checkData() and enterData() functions seem to be working fine, but make sure they are always returning the expected types.

Was this helpful?

More Salesforce discussions

Learn & Explore

Free tutorials and interview questions from industry experts — learn the skill, then get ready to prove it.

Latest Salesforce Blogs

Guides, tips and career advice on Salesforce from JanBask experts.