3

I am developing a Facebook Canvas application using django-facebook. When I used FacebookUserConverter.get_and_store_like(), it gives me this error:

[Errno 10061] No connection could be made because the target machine actively refused it

My app name is fbData, and fbData.models contains following classes:

from django.conf import settings
from django.db import models
from django.db.models.signals import post_save
from django.dispatch import receiver
from django_facebook.models import FacebookModel, get_user_model
from django_facebook.utils import get_profile_model
import logging
logger = logging.getLogger(__name__)


try:
    from django.contrib.auth.models import AbstractUser, UserManager
    class CustomFacebookUser(AbstractUser, FacebookModel):
    '''
    The django 1.5 approach to adding the facebook related fields
    '''
    objects = UserManager()
    # add any customizations you like

    middle_name = models.CharField(max_length=255, blank=True, null=True)
    verified = models.BooleanField(default=False) 
    locale = models.CharField(max_length=255, blank=True, null=True)
    languages = models.CharField(max_length=255, blank=True, null=True)
    link = models.CharField(max_length=255, blank=True, null=True)
    age_range = models.CharField(max_length=255, blank=True, null=True)
except ImportError, e:
    logger.info('Couldnt setup FacebookUser, got error %s', e)
    pass


# Create your models here.
class UserProfile(FacebookModel):
    '''
Inherit the properties from django facebook
'''
    user = models.OneToOneField(settings.AUTH_USER_MODEL)



@receiver(post_save)
def create_profile(sender, instance, created, **kwargs):
"""Create a matching profile whenever a user object is created."""
    if sender == get_user_model():
        user = instance
        profile_model = get_profile_model()
        if profile_model == UserProfile and created:
            profile, new = UserProfile.objects.get_or_create(user=instance)

my fbData.views is:

@facebook_required(canvas=True)
def home(request,graph):
    context = RequestContext(request)
    facebook_converter = FacebookUserConverter(graph)
    user_data = facebook_converter.facebook_registration_data(graph.get('me')['username'])


    user_data['access_token'] = graph.access_token
    try:

        fb_user = CustomFacebookUser.objects.get(facebook_id=user_data['facebook_id'])

        fb_user.access_token = user_data['access_token']
        fb_user.save()
        facebook_converter.get_and_store_likes(fb_user)       
    except CustomFacebookUser.DoesNotExist:
        custom_facebook_user = CustomFacebookUser(password = user_data['username'],username = user_data['username'],first_name = user_data['first_name'],last_name = user_data['last_name'],is_active = True, facebook_id = user_data['facebook_id'])
        custom_facebook_user.save()
        facebook_converter.get_and_store_likes(custom_facebook_user)

My settings.py contains:

CUSTOM_USER_MODEL = bool(int(os.environ.get('CUSTOM_USER_MODEL', '1')))

if DJANGO != '1.5.1':
    CUSTOM_USER_MODEL = False

if CUSTOM_USER_MODEL:
    AUTH_USER_MODEL = 'django_facebook.FacebookCustomUser'
else:
    AUTH_USER_MODEL = 'auth.User'
    AUTH_PROFILE_MODULE = 'fbData.UserProfile'

FACEBOOK_CELERY_STORE = True
FACEBOOK_CELERY_TOKEN_EXTEND = True
user3279360
  • 99
  • 10
Sijan Bhandari
  • 2,941
  • 3
  • 23
  • 36
  • "[Errno 10061] No connection could be made because the target machine actively refused it" This seems to indicate that the machine you're trying to connect to does not have a process listening on the port you're trying to connect on. How sure are you that the server process you expect is running? How sure are you that you're connecting on the right port number? – Tom Barron Apr 22 '14 at 22:35
  • It looks indeed to mee like Facebook is actively refusing your connection. Can you fetch anything else from facebook in your code? I don't know the OpenFacebook API really, but it looks like you need an access token to setup a connection (what you setup in "graph" I assume, but you don't provide the code). Is that token correct? – Dolf Andringa Jun 07 '14 at 17:52
  • What you could do is open up IDLE or any other interactive interpreter and just setup the Facebook connection there with the proper access token and see if you can get anything from facebook at all. – Dolf Andringa Jun 07 '14 at 17:53

0 Answers0