TypeError cannot unpack non-iterable NoneType object

1.0K    Asked by CarlPaige in Salesforce , Asked on Jul 29, 2021
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)


Answered by Caroline Brown

Hello, The “TypeError: cannot unpack non-iterable NoneType object” error is raised when you try to unpack values from one that is equal to None. A common cause of this error is when you try to unpack values from a function that does not return a value. To solve cannot unpack non-iterable nonetype object error, make sure the value you are trying to unpack is a sequence, such as a list or a tuple.



Your Answer

Interviews

Parent Categories