加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Python > 正文

python – Webapp2 get_user_by_password引发TypeError:无法连

发布时间:2020-12-20 11:36:13 所属栏目:Python 来源:网络整理
导读:我是webapp2的新手.我试图让自定义用户模型与身份验证系统兼容. 但每次我的程序调用get_user_by_password时都会引发TypeError:无法连接’str’和’NoneType’对象. 我甚至尝试用自定义模型运行某些elses应用程序,它也不会工作. 例如,我在这个项目 https://g
我是webapp2的新手.我试图让自定义用户模型与身份验证系统兼容.
但每次我的程序调用get_user_by_password时都会引发TypeError:无法连接’str’和’NoneType’对象.
我甚至尝试用自定义模型运行某些elses应用程序,它也不会工作.
例如,我在这个项目 https://gist.github.com/jgeewax/2942374中得到了同样的错误.

Traceback (most recent call last):
File "C:Program Files (x86)Googlegoogle_appenginelibwebapp2-2.5.2webapp2.py",line 1535,in __call__
rv = self.handle_exception(request,response,e)
File "C:Program Files (x86)Googlegoogle_appenginelibwebapp2-2.5.2webapp2.py",line 1529,in __call__
rv = self.router.dispatch(request,response)
File "C:Program Files (x86)Googlegoogle_appenginelibwebapp2-2.5.2webapp2.py",line 1278,in   default_dispatcher
return route.handler_adapter(request,line 1102,in __call__
return handler.dispatch()
File "D:STUDIASemestr 10Praca MagisterskaProjektytestmain.py",line 83,in dispatch
response = super(BaseHandler,self).dispatch()
File "C:Program Files (x86)Googlegoogle_appenginelibwebapp2-2.5.2webapp2.py",line 572,in dispatch
return self.handle_exception(e,self.app.debug)
File "C:Program Files (x86)Googlegoogle_appenginelibwebapp2-2.5.2webapp2.py",line 570,in dispatch
return method(*args,**kwargs)
File "D:STUDIASemestr 10Praca MagisterskaProjektytestmain.py",line 141,in post
self.auth.get_user_by_password(username,password)
File "C:Program Files (x86)Googlegoogle_appenginelibwebapp2-2.5.2webapp2_extrasauth.py",line 459,in get_user_by_password
silent=silent)
File "C:Program Files (x86)Googlegoogle_appenginelibwebapp2-2.5.2webapp2_extrasauth.py",line 278,in validate_password
return self.get_user_by_auth_password(auth_id,password,silent=silent)
File "C:Program Files (x86)Googlegoogle_appenginelibwebapp2-2.5.2webapp2_extrasauth.py",line 151,in get_user_by_auth_password
return self.user_to_dict(user)
File "C:Program Files (x86)Googlegoogle_appenginelibwebapp2-2.5.2webapp2_extrasauth.py",line 207,in user_to_dict
user_dict = dict((a,getattr(user,a)) for a in self.user_attributes)
File "C:Program Files (x86)Googlegoogle_appenginelibwebapp2-2.5.2webapp2_extrasauth.py",in <genexpr>
user_dict = dict((a,a)) for a in self.user_attributes)
File "C:Program Files (x86)Googlegoogle_appenginegoogleappengineextdb__init__.py",line 604,in __get__
return getattr(model_instance,self._attr_name())
File "C:Program Files (x86)Googlegoogle_appenginegoogleappengineextdb__init__.py",line 752,in _attr_name
return '_' + self.name
TypeError: cannot concatenate 'str' and 'NoneType' objects

解决方法

该错误说明您无法执行字符串(‘_’)和值为None的对象的字符串连接.这意味着此时self.name为None,因此您需要跟踪定义self.name的位置,以及是否正确存储值

如果您仍想连接这两个值,请考虑使用字符串格式而不是”符号.

例如,如果self.name值为None,则返回’_%s’%self.name将返回’_None’

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读