Hi Ken, thanks for your response. Here is the src.
views.py:
class UserViewSet(viewsets.ModelViewSet):
"""
List all users for either the company of current authenticated user or for a requested group.
Example: /api/v1/users/ or /api/v1/users/?group_id=5
"""
serializer_class = UserSerializer
authentication_classes = [TokenAuthentication, SessionAuthentication]
permission_classes = [PermissionsCheck]
def get_queryset(self):
group_id = self.request.query_params.get('group_id', None)
user = self.request.user
if group_id:
return User.objects.select_related("groupmember").filter(group_id=user.current_group_id)
else:
return user.get_company_members()
permissions.py
class PermissionsCheck(permissions.BasePermission):
"""
Checks supervisor and superuser perms
"""
def has_permission(self, request, view):
user = request.user
if user :
return user.is_supervisor() or user.is_superuser()
else:
return False
Here is the full error log:
Internal Server Error: /api/users/
Traceback (most recent call last):
File "C:\Users\mthomas\AppData\Local\Programs\Python\Python310\lib\site-packages\rest_framework\authentication.py", line 201, in authenticate_credentials
token = model.objects.select_related('user').get(key=key)
AttributeError: type object 'Token' has no attribute 'objects'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\mthomas\AppData\Local\Programs\Python\Python310\lib\site-packages\rest_framework\request.py", line 74, in wrap_attributeerrors
yield
File "C:\Users\mthomas\AppData\Local\Programs\Python\Python310\lib\site-packages\rest_framework\request.py", line 231, in user
self._authenticate()
File "C:\Users\mthomas\AppData\Local\Programs\Python\Python310\lib\site-packages\rest_framework\request.py", line 384, in _authenticate
user_auth_tuple = authenticator.authenticate(self)
File "C:\Users\mthomas\AppData\Local\Programs\Python\Python310\lib\site-packages\rest_framework\authentication.py", line 196, in authenticate
return self.authenticate_credentials(token)
File "C:\Users\mthomas\AppData\Local\Programs\Python\Python310\lib\site-packages\rest_framework\authentication.py", line 202, in authenticate_credentials
except model.DoesNotExist:
AttributeError: type object 'Token' has no attribute 'DoesNotExist'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "C:\Users\mthomas\AppData\Local\Programs\Python\Python310\lib\site-packages\django\core\handlers\exception.py", line 55, in inner
response = get_response(request)
File "C:\Users\mthomas\AppData\Local\Programs\Python\Python310\lib\site-packages\django\core\handlers\base.py", line 197, in _get_response
response = wrapped_callback(request, *callback_args, **callback_kwargs)
File "C:\Users\mthomas\AppData\Local\Programs\Python\Python310\lib\site-packages\django\views\decorators\csrf.py", line 65, in _view_wrapper
return view_func(request, *args, **kwargs)
File "C:\Users\mthomas\AppData\Local\Programs\Python\Python310\lib\site-packages\rest_framework\viewsets.py", line 124, in view
return self.dispatch(request, *args, **kwargs)
File "C:\Users\mthomas\AppData\Local\Programs\Python\Python310\lib\site-packages\rest_framework\views.py", line 509, in dispatch
response = self.handle_exception(exc)
File "C:\Users\mthomas\AppData\Local\Programs\Python\Python310\lib\site-packages\rest_framework\views.py", line 469, in handle_exception
self.raise_uncaught_exception(exc)
File "C:\Users\mthomas\AppData\Local\Programs\Python\Python310\lib\site-packages\rest_framework\views.py", line 480, in raise_uncaught_exception
raise exc
File "C:\Users\mthomas\AppData\Local\Programs\Python\Python310\lib\site-packages\rest_framework\views.py", line 497, in dispatch
self.initial(request, *args, **kwargs)
File "C:\Users\mthomas\AppData\Local\Programs\Python\Python310\lib\site-packages\rest_framework\views.py", line 414, in initial
self.perform_authentication(request)
File "C:\Users\mthomas\AppData\Local\Programs\Python\Python310\lib\site-packages\rest_framework\views.py", line 324, in perform_authentication
request.user
File "C:\Users\mthomas\AppData\Local\Programs\Python\Python310\lib\site-packages\rest_framework\request.py", line 230, in user
with wrap_attributeerrors():
File "C:\Users\mthomas\AppData\Local\Programs\Python\Python310\lib\contextlib.py", line 153, in __exit__
self.gen.throw(typ, value, traceback)
File "C:\Users\mthomas\AppData\Local\Programs\Python\Python310\lib\site-packages\rest_framework\request.py", line 78, in wrap_attributeerrors
raise exc.with_traceback(info[2])
File "C:\Users\mthomas\AppData\Local\Programs\Python\Python310\lib\site-packages\rest_framework\request.py", line 74, in wrap_attributeerrors
yield
File "C:\Users\mthomas\AppData\Local\Programs\Python\Python310\lib\site-packages\rest_framework\request.py", line 231, in user
self._authenticate()
File "C:\Users\mthomas\AppData\Local\Programs\Python\Python310\lib\site-packages\rest_framework\request.py", line 384, in _authenticate
user_auth_tuple = authenticator.authenticate(self)
File "C:\Users\mthomas\AppData\Local\Programs\Python\Python310\lib\site-packages\rest_framework\authentication.py", line 196, in authenticate
return self.authenticate_credentials(token)
File "C:\Users\mthomas\AppData\Local\Programs\Python\Python310\lib\site-packages\rest_framework\authentication.py", line 202, in authenticate_credentials
except model.DoesNotExist:
rest_framework.request.WrappedAttributeError: type object 'Token' has no attribute 'DoesNotExist'
It should also be noted that session based authentication works fine, and I am able to access the endpoint from the web interface.
Thanks!