如何处理Python Social Auth中的异常 [英] How do I handle exceptions on Python Social Auth

查看:135
本文介绍了如何处理Python Social Auth中的异常的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何处理这种异常 AuthAlreadyAssociated on Python Social Auth

How do I handle this kind of exception AuthAlreadyAssociated on Python Social Auth?

我发现的所有答案都是针对 Django Social Auth ,但自写入以来似乎有很多变化。

All the answers I found are for Django Social Auth but it seems plenty has changed ever since they were written.

推荐答案

这对我有用。

我创建了一个新的中间件

I create a new middleware

from social.apps.django_app.middleware import SocialAuthExceptionMiddleware
from django.http import HttpResponse
from social import exceptions as social_exceptions     

class MySocialAuthExceptionMiddleware(SocialAuthExceptionMiddleware):
    def process_exception(self, request, exception):
        if hasattr(social_exceptions, exception.__class__.__name__):
            return HttpResponse("catched: %s" % exception)
        else:
            raise exception

并将其添加到settings.py

and add it to settings.py

MIDDLEWARE_CLASSES = (
    ...
    'path.to.MySocialAuthExceptionMiddleware',
   )

这篇关于如何处理Python Social Auth中的异常的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆