It's something about Django. I don't know if it is expected behavior or not, hence I created a ticket <https://code.djangoproject.com/ticket/27706>.
Regards On Monday, January 9, 2017 at 12:25:03 AM UTC+3, Andrew Godwin wrote: > > Hi, > > Have you tried removing the "channels" package from INSTALLED_APPS and > making sure it fails without that as well? > > Andrew > > On Sun, Jan 8, 2017 at 1:43 AM, Utku Gültopu <[email protected] > <javascript:>> wrote: > >> When I log a user in using django.contrib.auth.login function, >> session_key is sometimes not set in the request of the view. >> >> Code in views.py: >> >> from django.contrib import auth >> from django.contrib.auth.models import User >> from django.http import HttpResponse >> import json >> >> def login(request): >> username = request.POST['username'] >> password = request.POST['password'] >> user = auth.authenticate(username=username, password=password) >> if user is not None: >> try: >> auth.login(request, user) >> session_key = request.session.session_key >> if session_key is not None: >> return HttpResponse(json.dumps({'status': 'Success', >> 'sessionid': session_key})) >> else: >> return HttpResponse(json.dumps({'status': 'Empty session >> key'})) >> except Exception as e: >> return HttpResponse(json.dumps({'status': 'Cannot log in'})) >> else: >> return HttpResponse(json.dumps({'status': 'Cannot authenticate'})) >> >> When I try to log in an existing user with this code, sometimes I will >> get the Empty session key response. In those cases, I resend the exact >> same request and this time, session key is successfully set. >> >> What is the reason for this? What am I missing here? >> >> I am using Django Channels development server and stunnel >> <https://www.stunnel.org/> as the SSL proxy. >> >> Regards >> >> -- >> You received this message because you are subscribed to the Google Groups >> "Django users" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected] <javascript:>. >> To post to this group, send email to [email protected] >> <javascript:>. >> Visit this group at https://groups.google.com/group/django-users. >> To view this discussion on the web visit >> https://groups.google.com/d/msgid/django-users/71a47486-fdad-4da3-8baa-608ce66e8676%40googlegroups.com >> >> <https://groups.google.com/d/msgid/django-users/71a47486-fdad-4da3-8baa-608ce66e8676%40googlegroups.com?utm_medium=email&utm_source=footer> >> . >> For more options, visit https://groups.google.com/d/optout. >> > > -- You received this message because you are subscribed to the Google Groups "Django users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/django-users. To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/464c59f1-4619-4ae5-9132-15048ca6867f%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.

