I am having a problem with my authentication / login. This system worked before, but recently I switched to a new server and cannot fix it.
When trying to log in through auth-view request.user is always an anonymous user, as if I did not upload any credentials. I tried logging the .POST request, but it seems empty.
I have a trace here:
Environment: Request Method: POST Request URL: http://45.55.149.3:8000/api/auth/ Django Version: 1.8.3 Python Version: 2.7.6 Installed Applications: ('django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', 'webapp', 'rest_framework', 'djrill') 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 "/home/appointments-app/venv/local/lib/python2.7/site-packages/django/core/handlers/base.py" in get_response 132. response = wrapped_callback(request, *callback_args, **callback_kwargs) File "/home/appointments-app/venv/local/lib/python2.7/site-packages/django/views/decorators/csrf.py" in wrapped_view 58. return view_func(*args, **kwargs) File "/home/appointments-app/venv/local/lib/python2.7/site-packages/django/views/generic/base.py" in view 71. return self.dispatch(request, *args, **kwargs) File "/home/appointments-app/venv/local/lib/python2.7/site-packages/rest_framework/views.py" in dispatch 456. response = self.handle_exception(exc) File "/home/appointments-app/venv/local/lib/python2.7/site-packages/rest_framework/views.py" in dispatch 453. response = handler(request, *args, **kwargs) File "/home/appointments-app/appointments/webapp/views.py" in post 40. login(request, request.user) File "/home/appointments-app/venv/local/lib/python2.7/site-packages/django/contrib/auth/__init__.py" in login 111. request.session[SESSION_KEY] = user._meta.pk.value_to_string(user) Exception Type: AttributeError at /api/auth/ Exception Value: 'AnonymousUser' object has no attribute '_meta'
Here I have an API authenticator that does not work:
class AuthView(APIView): authentication_classes = (QuietBasicAuthentication,) def post(self, request, *args, **kwargs): login(request, request.user) return Response(OldUserSerializer(request.user).data) def delete(self, request, *args, **kwargs): logout(request) return Response({})
below is the authentication class I'm using:
from rest_framework.authentication import BasicAuthentication class QuietBasicAuthentication(BasicAuthentication):