Closed patvdleer closed 9 years ago
'TokenAuthentication' object has no attribute 'has_permission' error on api-root
'TokenAuthentication' object has no attribute 'has_permission'
urls.py
from django.conf.urls import include, url from rest_framework_nested import routers from rest_framework.authtoken import views as authtoken_views from Api.views import ChannelViewSet, ChannelFieldViewSet, FieldValueViewSet, GroupViewSet, UserViewSet router = routers.DefaultRouter() router.register(r'users', UserViewSet) router.register(r'groups', GroupViewSet) router.register(r'channels', ChannelViewSet) channel_router = routers.NestedSimpleRouter(router, r'channels', lookup='channel') channel_router.register(r'fields', ChannelFieldViewSet, base_name='channel-fields') fields_router = routers.NestedSimpleRouter(channel_router, r'fields', lookup='field') fields_router.register(r'values', FieldValueViewSet, base_name='values') urlpatterns = [ url(r'^', include(router.urls)), url(r'^', include(channel_router.urls)), url(r'^', include(fields_router.urls)), url(r'^api-auth/', include('rest_framework.urls', namespace='rest_framework')), url(r'^api-token-auth/', authtoken_views.obtain_auth_token) ]
Traceback
Environment: Request Method: GET Request URL: http://127.0.0.1:8000/api/ Django Version: 1.8.5 Python Version: 3.4.3 Installed Applications: ('django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'django_jinja', 'rest_framework', 'rest_framework.authtoken', 'IoT', 'Api', 'Dashboard') Installed Middleware: ('django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.auth.middleware.SessionAuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware', 'django.middleware.security.SecurityMiddleware') Traceback: File "/usr/local/lib/python3.4/dist-packages/django/core/handlers/base.py" in get_response 132. response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/usr/local/lib/python3.4/dist-packages/django/views/decorators/csrf.py" in wrapped_view 58. return view_func(*args, **kwargs) File "/usr/local/lib/python3.4/dist-packages/django/views/generic/base.py" in view 71. return self.dispatch(request, *args, **kwargs) File "/usr/local/lib/python3.4/dist-packages/rest_framework/views.py" in dispatch 466. response = self.handle_exception(exc) File "/usr/local/lib/python3.4/dist-packages/rest_framework/views.py" in dispatch 454. self.initial(request, *args, **kwargs) File "/usr/local/lib/python3.4/dist-packages/rest_framework/views.py" in initial 377. self.check_permissions(request) File "/usr/local/lib/python3.4/dist-packages/rest_framework/views.py" in check_permissions 318. if not permission.has_permission(request, self): Exception Type: AttributeError at /api/ Exception Value: 'TokenAuthentication' object has no attribute 'has_permission'
has_permission is for permissions. TokenAuthentication is for authentication. Looks like you have a typo/mismatch.
has_permission
TokenAuthentication
'TokenAuthentication' object has no attribute 'has_permission'
error on api-rooturls.py
Traceback