AttributeError:'DjangoStrategy'对象没有属性'后端'python社会认证

编程入门 行业动态 更新时间:2024-10-26 11:18:14
本文介绍了AttributeError:'DjangoStrategy'对象没有属性'后端'python社会认证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

上周工作。也许我做错了事情,把它搞砸了,或许这是一个错误,或者也许只是一个更新,我在阅读文档时错过了。

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 = 'graph.facebook/{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 = 'graph.facebook/{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社会认证

本文发布于:2023-10-22 08:14:34,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1516958.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:后端   属性   对象   社会   AttributeError

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!