stacklens / dusai-blog

杜赛的博客的评论区。详情见 Issue。
2 stars 0 forks source link

article/66/ #35

Open stacklens opened 4 years ago

stacklens commented 4 years ago

https://www.dusaiphoto.com/article/66/

stacklens commented 4 years ago

旧评论区读者问题集中帖:


Q:git头像是怎么获取的?

A:user.socialaccount_set.all.0.get_avatar_url

用django-allauth第三方登录会返回很多数据,比如用户头像、性别、年龄等,这些在后台里都能查的到的。

bode135 commented 3 years ago

我这github失败... 换baidu的也失败.. 就第一次能正确转到等三方授权页面, 然后就显示KeyError at /accounts/github/login/callback/

错误信息:

image-20210221200058235

求指点 T . T

stacklens commented 3 years ago

我这github失败... 换baidu的也失败.. 就第一次能正确转到等三方授权页面, 然后就显示KeyError at /accounts/github/login/callback/

错误信息:

image-20210221200058235

求指点 T . T

把缓存清了呢?

stacklens commented 3 years ago

我这github失败... 换baidu的也失败.. 就第一次能正确转到等三方授权页面, 然后就显示KeyError at /accounts/github/login/callback/

错误信息:

image-20210221200058235

求指点 T . T

把缓存清了呢?

bode135 commented 3 years ago

我这github失败... 换baidu的也失败.. 就第一次能正确转到等三方授权页面, 然后就显示KeyError at /accounts/github/login/callback/ 错误信息: image-20210221200058235 求指点 T . T

把缓存清了呢?

换了台机器重新部署了一遍还是这样... 验证成功了, github也发来了邮件提示已经完成授权...

A third-party OAuth application (django第三方登录) with access to public information (read-only) was recently authorized to access your account. 然后就这个页面了.... 重新登录也一样, 也尝试了清除缓存... 是不是因为项目里面没有保存用户信息的部分呢? 所以对callback没有相应的处理..?

bode135 commented 3 years ago

''' def extract_uid(self, data): return str(data['id']) # 提示是这里出现了错误, 导致 uid = self.extract_uid(response) 错误 def extract_common_fields(self, data): return dict(email=data.get('email'), username=data.get('login'), name=data.get('name'))

'''

好像是它某个函数需要的data字典里面没有'key值'为'id', 所以报错....

bode135 commented 3 years ago

昨晚上换了百度的oauth接口也是这样=- =

bode135 commented 3 years ago

额, 我昨天clone了你的django-blog-tutorial项目, 然后也是一样显示这个错误.... 可能感觉我的安装包版本出了问题

stacklens commented 3 years ago

额, 我昨天clone了你的django-blog-tutorial项目, 然后也是一样显示这个错误.... 可能感觉我的安装包版本出了问题

有这个可能。比如 Django 版本和库的版本对应不上,或者这个库已经没维护了。毕竟教程都是几年前写的

jwcen commented 3 years ago

求大佬帮忙看看,这字段该怎么改啊

jwcen commented 3 years ago

大佬,这个id问题我弄了一天都没整出来,求助大佬!

KeyError at /accounts/github/login/callback/
'id'
Request Method: GET
Request URL:    http://127.0.0.1:8000/accounts/github/login/callback/?code=39d44993c0b6a733e9ba&state=DFUD7398HPdK
Django Version: 2.2.13
Exception Type: KeyError
Exception Value:    
'id'
Exception Location: D:\myMajor\workstation\django_blog\env\lib\site-packages\allauth\socialaccount\providers\github\provider.py in extract_uid, line 38
Python Executable:  D:\myMajor\workstation\django_blog\env\Scripts\python.exe
Python Version: 3.7.0
Python Path:    
['D:\\myMajor\\workstation\\django_blog',
 'D:\\myMajor\\workstation\\django_blog\\env\\Scripts\\python37.zip',
 'D:\\softwares\\Anaconda3\\DLLs',
 'D:\\softwares\\Anaconda3\\lib',
 'D:\\softwares\\Anaconda3',
 'D:\\myMajor\\workstation\\django_blog\\env',
 'D:\\myMajor\\workstation\\django_blog\\env\\lib\\site-packages']
Server time:    Sat, 24 Apr 2021 22:46:56 +0800
bode135 commented 3 years ago

求大佬帮忙看看,这字段该怎么改啊

别慌, 两个月了我也还是没弄出来哈哈哈哈哈哈

现在改用vue+DRF前后分离写项目了, 最近刚忙完, 回来重新研究下第三方登录.

bode135 commented 3 years ago

大兄弟你这找出问题来了么~

cj919837775 commented 3 years ago

我也卡在这里。。。 难搞哦

bode135 commented 2 years ago

时隔半年, 重新拿起这个项目. 解决方案就是自己手撸Oauth2的api.

内网github老是来大姨妈, 各种问题... 最后接入了gitee和qq第三方登录. 推荐先用gitee试水, 审核简单, 做demo很合适. QQ断断续续申请了几个月还没过审核...

liuzzz2017 commented 2 years ago

ERROR: Could not install packages due to an OSError: [WinError 5] 拒绝访问。: 'C:\Users\xxxxxxx\AppData\Local\Temp\pip-install -t050pipw\django-allauth_7bbcc6a7fa4d4a4f8ba0154872f83a34\allauth/socialaccount/providers/baidu' Check the permissions.

不管我怎么搞,它就是报这个错

liuzzz2017 commented 2 years ago

由于是py3.10,换到py3.9试试,django3.2,但错误基本上还是一样的: build\lib\allauth\socialaccount\providers\authentiq creating build\lib\allauth\socialaccount\providers\azure copying allauth\socialaccount\providers\azure\models.py -> build\lib\allauth\socialaccount\providers\azure copying allauth\socialaccount\providers\azure\provider.py -> build\lib\allauth\socialaccount\providers\azure copying allauth\socialaccount\providers\azure\tests.py -> build\lib\allauth\socialaccount\providers\azure copying allauth\socialaccount\providers\azure\urls.py -> build\lib\allauth\socialaccount\providers\azure copying allauth\socialaccount\providers\azure\views.py -> build\lib\allauth\socialaccount\providers\azure copying allauth\socialaccount\providers\azure__init__.py -> build\lib\allauth\socialaccount\providers\azure creating build\lib\allauth\socialaccount\providers\baidu error: could not create 'build\lib\allauth\socialaccount\providers\baidu': 拒绝访问。 [end of output]

note: This error originates from a subprocess, and is likely not a problem with pip. error: legacy-install-failure

Encountered error while trying to install package.

真的想不出怎么搞定了, 或者有没有其它allauth的库?

individualCodeSpace commented 2 years ago

请问最后一步遇到这个问题是什么原因呢?

individualCodeSpace commented 2 years ago

error info: You are about to sign in using a third party account from GitHub.

individualCodeSpace commented 2 years ago

error info: An error occurred while attempting to login via your social network account.

individualCodeSpace commented 2 years ago

错误打印出来是这样的

Environment:

Request Method: POST Request URL: http://127.0.0.1:8000/accounts/github/login/?process=login

Django Version: 2.2 Python Version: 3.7.0 Installed Applications: ['django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.sites', 'django.contrib.staticfiles', 'password_reset', 'allauth', 'allauth.account', 'allauth.socialaccount', 'allauth.socialaccount.providers.github', 'allauth.socialaccount.providers.weibo', 'article', 'userprofile', 'comment', 'taggit', 'ckeditor', 'mptt', 'notifications', 'notice'] Installed Middleware: ['django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', 'django.middleware.common.CommonMiddleware', 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', 'django.contrib.messages.middleware.MessageMiddleware', 'django.middleware.clickjacking.XFrameOptionsMiddleware']

Traceback:

File "E:\django_project\env\lib\site-packages\django\core\handlers\exception.py" in inner

  1. response = get_response(request)

File "E:\django_project\env\lib\site-packages\django\core\handlers\base.py" in _get_response

  1. response = self.process_exception_by_middleware(e, request)

File "E:\django_project\env\lib\site-packages\django\core\handlers\base.py" in _get_response

  1. response = wrapped_callback(request, *callback_args, **callback_kwargs)

File "E:\django_project\env\lib\site-packages\allauth\socialaccount\providers\oauth2\views.py" in view

  1. return self.dispatch(request, *args, **kwargs)

File "E:\django_project\env\lib\site-packages\allauth\socialaccount\providers\base\mixins.py" in dispatch

  1. return self.login(request, *args, **kwargs)

File "E:\django_project\env\lib\site-packages\allauth\socialaccount\providers\oauth2\views.py" in login

  1. app = provider.get_app(self.request)

File "E:\django_project\env\lib\site-packages\allauth\socialaccount\providers\base\provider.py" in get_app

  1. adapter = get_adapter(request)

File "E:\django_project\env\lib\site-packages\allauth\socialaccount\adapter.py" in get_adapter

  1. return import_attribute(app_settings.ADAPTER)(request)

File "E:\django_project\env\lib\site-packages\allauth\utils.py" in import_attribute

  1. ret = getattr(importlib.import_module(pkg), attr)

File "C:\Users\Administrator\AppData\Local\Programs\Python\Python37\Lib\importlib__init__.py" in import_module

  1. return _bootstrap._gcd_import(name[level:], package, level)

File "" in _gcd_import

File "" in _find_and_load

File "" in _find_and_load_unlocked

File "" in _call_with_frames_removed

File "" in _gcd_import

File "" in _find_and_load

File "" in _find_and_load_unlocked

Exception Type: ModuleNotFoundError at /accounts/github/login/ Exception Value: No module named 'main'

YOLOMIN commented 1 year ago

在django2.2的环境需要指定安装对应版本: pip install django-allauth==0.54.0