0

I think I have set up my code quite properly but I'm getting this error for some reason. The code:

def publicfiles (request):
    userobj = request.session.get('uid')
    filenamearr = []
    filelinkarr = []
    timearr = []
    uploaderarr = [] 
    x = db.child("files").child("public").get()
    for user in x.each():
        print (user.key())
        y = db.child("files").child("public").child(user.key()).get()
        userlist = []
        
        for docs in y.each():
            userlist.append(docs.key())
            userlist.append(docs.val())
        
        filenamearr.append(userlist[0])
        filelinkarr.append(pyrestorage.child(userlist[1]).get_url(None))
        timearr.append(userlist[3])
        uploaderarr.append(userlist[5])
    
    print(filenamearr)
    print(filelinkarr)
    print(timearr)
    print(uploaderarr)

    return render(request, 'dashboard/public/datatabledash.html', 
    {'name': filenamearr, 'link': filelinkarr, 'time': timearr, 'uploader': uploaderarr})

can anyone help me why I get TypeError: 'NoneType' object is not iterable in for docs in y.each() ?

Max Damage
  • 31
  • 1
  • 6
  • Does this answer your question? [TypeError: 'NoneType' object is not iterable in Python](https://stackoverflow.com/questions/3887381/typeerror-nonetype-object-is-not-iterable-in-python) – awesoon May 09 '21 at 18:50
  • I already checked this but according to this if one of my variables returns a none type data field then such exceptions happen but as I am working in django, I checked my local variables and it shows all values exactly as it should, problem is I cannot render the next page because of this error. – Max Damage May 09 '21 at 19:36
  • 1
    The next option is to debug, before the line `for docs in y.each():` put a print statement to see what are the values in y and as suspect, it will None for the error. then check your logic for `y = db.child("files").child("public").child(user.key()).get()`. Or provide data so that we can run the function `publicfiles` to reproduce it. – simpleApp May 10 '21 at 03:25
  • 1
    "if one of my variables returns a none type data field then such exceptions happen" - not any, but exactly `y.each()` is returning `None` – awesoon May 10 '21 at 06:28
  • It was an issue with my firebase realtime database structure, that's why such error occured. The code works fine until a certain structure breaks the structure that's why it happened. Thank you everyone that helped. – Max Damage May 10 '21 at 11:07

0 Answers0