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]> 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].
> 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/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/CAFwN1urcP9oV5Zku%3DtTXry%2BFaNNRHCTQkJz%3Dkc9gX4FjNL5jzg%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to