Search code examples
djangopython-social-auth

django python social auth send email


I am using python social auth for login. After user is created I want to send the user a email. For this I am writing a custom pipeline

def send_confirmation_email(strategy, details, response, user=None, *args, **kwargs):
if user:
    if kwargs['is_new']:
        template = "email/social_registration_confirm.html"
        subject = "Account Confirmation"
        email = user.email
        print(user.username)
        username = user.username
        kwargs.update(subject=subject, email=email, username=username)
        notification_email.delay(template, **kwargs)

I am using celery to send email. When I send email it gives me error saying <UserSocialAuth: some_username> is not JSON serializable

Why I am getting this error. notification_email works for other email sending functionality.

Need suggestion. Thank you


Solution

  • JSON accepts only a few datatypes: null, arrays, booleans, numbers, strings, and objects.

    So, anything else should be expressed as one of these types.

    My guess is that **kwargs that you are sending in to notification_email contains a data type that cannot be expressed as JSON.

    To solve this problem, send only needed arguments, not the whole **kwargs.

    I would create a dictionary and include everything there:

    var args = dict()
    
    args['username'] = username
    args['template'] = template
    # other arguments
    
    notification_email.delay(args)
    

    I hope it helps.