djangofacebookcanvasdjango-facebook

Why the request.user is AnonymousUser in my django-facebook canvas application?


I am developing a Facebook canvas application using the frameworks django_facebook.

I want to save the user data in my local database.

@facebook_required(canvas=True)
def home(request,graph):

    facebook = FacebookUserConverter(graph)
    facebook_converter = FacebookUserConverter(graph)
    user_data = facebook_converter.facebook_registration_data(graph.get('me'    ['username'])
    print request.user //AnonymousUser
    facebook_converter.get_and_store_friends(request.user) //This creates error

And it gives me error "[Errno 10061] No connection could be made because the target machine actively refused it" When I trace back, I found that request.user is AnonymousUser.


Solution

  • This happens when user is not logged in.

    request.user by default is a SimpleLazyObject which evaluates to the logged in user, if user is logged in. If not, it evaluates to AnonymousUser hence the error.