AttributeError:'DjangoStrategy'对象没有属性'后端'python社会认证 [英] AttributeError: 'DjangoStrategy' object has no attribute 'backend' python social auth
问题描述
上周工作。也许我做错了事情,把它搞砸了,或许这是一个错误,或者也许只是一个更新,我在阅读文档时错过了。
This worked last week. Maybe I did something wrong and messed it up somewhere else, or maybe it is a bug, or maybe it is just an update and I missed it while reading the docs.
我有一个管道可以获取用户头像并保存URL:
I have a pipeline that gets the user's avatar and saves the URL:
def get_avatar(strategy, details, response, user, *args, **kwargs):
url = None
if strategy.backend.name == 'facebook':
url = 'http://graph.facebook.com/{0}/picture'.format(response['id'])
elif strategy.backend.name == "twitter":
if response['profile_image_url'] != '':
url = response['profile_image_url']
elif strategy.backend.name == "google-oauth2":
if response['image'].get('url') is not None:
url = response['image'].get('url')
现在,它给了我错误:
'DjangoStrategy' object has no attribute 'backend'
请帮助,一些测试版用户已经在使用我的网站,
Please help, some beta users are already using my website and for the moment, they don't have a profile image.
推荐答案
好的,所以我会发布我发现的解决方案,以防万一有同样的问题。我不知道这是否是最好的方法,但它的作用是:
Ok, so I will post the solution I found just in case someone has the same problem. I am not sure if this is the best way to do it, but it works:
if "facebook" in kwargs['backend'].redirect_uri:
url = 'http://graph.facebook.com/{0}/picture'.format(response['id'])
elif "twitter" in kwargs['backend'].redirect_uri:
if response['profile_image_url'] != '':
url = response['profile_image_url']
elif "google" in kwargs['backend'].redirect_uri:
if response['image'].get('url') is not None:
url = response['image'].get('url')
欢迎其他解决方案。
这篇关于AttributeError:'DjangoStrategy'对象没有属性'后端'python社会认证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!