Reputation: 31
I'm new to webapp2. I've tried to make a custom user model compilant with authentication system. But every time my program calls get_user_by_password it raises an TypeError: cannot concatenate 'str' and 'NoneType' objects. I've tried even to run somebody elses applications with custom models and it won't work neither. For example I get the same error with this project https://gist.github.com/jgeewax/2942374.
Traceback (most recent call last):
File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 1535, in __call__
rv = self.handle_exception(request, response, e)
File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 1529, in __call__
rv = self.router.dispatch(request, response)
File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 1278, in default_dispatcher
return route.handler_adapter(request, response)
File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 1102, in __call__
return handler.dispatch()
File "D:\STUDIA\Semestr 10\Praca Magisterska\Projekty\test\main.py", line 83, in dispatch
response = super(BaseHandler, self).dispatch()
File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 572, in dispatch
return self.handle_exception(e, self.app.debug)
File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2.py", line 570, in dispatch
return method(*args, **kwargs)
File "D:\STUDIA\Semestr 10\Praca Magisterska\Projekty\test\main.py", line 141, in post
self.auth.get_user_by_password(username, password)
File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2_extras\auth.py", line 459, in get_user_by_password
silent=silent)
File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2_extras\auth.py", line 278, in validate_password
return self.get_user_by_auth_password(auth_id, password, silent=silent)
File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2_extras\auth.py", line 151, in get_user_by_auth_password
return self.user_to_dict(user)
File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2-2.5.2\webapp2_extras\auth.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)\Google\google_appengine\lib\webapp2-2.5.2\webapp2_extras\auth.py", line 207, in <genexpr>
user_dict = dict((a, getattr(user, a)) for a in self.user_attributes)
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\db\__init__.py", line 604, in __get__
return getattr(model_instance, self._attr_name())
File "C:\Program Files (x86)\Google\google_appengine\google\appengine\ext\db\__init__.py", line 752, in _attr_name
return '_' + self.name
TypeError: cannot concatenate 'str' and 'NoneType' objects
Upvotes: 3
Views: 18434
Reputation: 708
The error explains that you cannot perform string concatenation of a string ('_'
) and an object which value is None
. It means at this point self.name
is None
, so you need to trace where self.name
is being defined, and if you are storing the value correctly
If you still want to concatenate the two values, consider using string formatting instead of the '+' sign.
eg return '_%s' % self.name
would return '_None'
if self.name
value is None
Upvotes: 7