Search code examples
pythontraceback

Python stack trace interpretation - 'NoneType' object is not iterable, but no loop


I have this exception in the view of a django application. But I think my issue is not connected to django at all. It's a python thing:

Traceback:

File "/home/ubuntu/app/.venv/lib/python3.5/site-packages/django/core/handlers/exception.py" in inner
  35.             response = get_response(request)

File "/home/ubuntu/app/.venv/lib/python3.5/site-packages/django/core/handlers/base.py" in _get_response
  128.                 response = self.process_exception_by_middleware(e, request)

File "/home/ubuntu/app/.venv/lib/python3.5/site-packages/django/core/handlers/base.py" in _get_response
  126.                 response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "/home/ubuntu/app/frontend/views.py" in ajax_patient_pm
  2977.         (gstatus, gmessage) = grecaptcha_verify(request)

Exception Type: TypeError at /de/ajax/contactpatientpm/
Exception Value: 'NoneType' object is not iterable
Request information:
USER: AnonymousUser

GET: No GET data

POST: No POST data

FILES: No FILES data

COOKIES: No cookie data

This Traceback puzzles me. There is no loop. I don't see where None in any of the variables would hurt.

Can anybody shed some light on that?


Solution

  • 'NoneType' object is not iterable is commonly encountered when trying to iterate over None, but it can also occur when trying to perform sequence unpacking on None, like this:

    >>> x, y = None
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: 'NoneType' object is not iterable