Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django rest framework " TypeError: 'type' object is not iterable " error

I do not know what configuration to modify.

My git repository URL is: https://github.com/Nomadcoders-Study/Nomadgram

Internal Server Error: /images/all/
Traceback (most recent call last):
  File "/usr/local/var/pyenv/versions/3.6.1/envs/nomadgram/lib/python3.6/site-packages/django/core/handlers/exception.py", line 41, in inner
response = get_response(request)
  File "/usr/local/var/pyenv/versions/3.6.1/envs/nomadgram/lib/python3.6/site-packages/django/core/handlers/base.py", line 187, in _get_response
response = self.process_exception_by_middleware(e, request)
  File "/usr/local/var/pyenv/versions/3.6.1/envs/nomadgram/lib/python3.6/site-packages/django/core/handlers/base.py", line 185, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
  File "/usr/local/var/pyenv/versions/3.6.1/envs/nomadgram/lib/python3.6/site-packages/django/views/decorators/csrf.py", line 58, in wrapped_view
return view_func(*args, **kwargs)
  File "/usr/local/var/pyenv/versions/3.6.1/envs/nomadgram/lib/python3.6/site-packages/django/views/generic/base.py", line 68, in view
return self.dispatch(request, *args, **kwargs)
  File "/usr/local/var/pyenv/versions/3.6.1/envs/nomadgram/lib/python3.6/site-packages/rest_framework/views.py", line 478, in dispatch
request = self.initialize_request(request, *args, **kwargs)
  File "/usr/local/var/pyenv/versions/3.6.1/envs/nomadgram/lib/python3.6/site-packages/rest_framework/views.py", line 380, in initialize_request
authenticators=self.get_authenticators(),
  File "/usr/local/var/pyenv/versions/3.6.1/envs/nomadgram/lib/python3.6/site-packages/rest_framework/views.py", line 274, in get_authenticators
  return [auth() for auth in self.authentication_classes]
TypeError: 'type' object is not iterable
like image 875
Nouveau Avatar asked Nov 27 '18 08:11

Nouveau


People also ask

How do I fix TypeError type object is not iterable?

The Python "TypeError: 'type' object is not iterable" occurs when we try to iterate over a class that is not iterable, e.g. forget to call the range() function. To solve the error, make the class iterable by implementing the __iter__() method.

What is caching in Django REST framework?

Caching something is to save the result of an expensive calculation so that we don't have to perform the calculation next time. We will discuss the caching in Django REST framework step by step: Caching Concept. Setting up the Memcached. Adding Cache Config in settings.py.


1 Answers

On the settings.py file append comma at the end of '...JSONWebTokenAuthentication' line as below:

REST_FRAMEWORK = {
    'DEFAULT_PERMISSION_CLASSES': (
        'rest_framework.permissions.IsAuthenticated',
    ),
    'DEFAULT_AUTHENTICATION_CLASSES': (
        'rest_framework_jwt.authentication.JSONWebTokenAuthentication',
    ),
}

Attention: without comma this is not a tuple

like image 178
M.javid Avatar answered Sep 29 '22 21:09

M.javid