I am playing around with Google App Engine and I am simply trying to increment a value by 1 (player.number_requests — see code below). However, when I do so, I am getting the following error: “TypeError: can only concatenate tuple (not “int”) to tuple”. Any idea why this is happening?
class Player(db.Model):
name = db.StringProperty(required=True, multiline=False),
number_requests = db.IntegerProperty(required=True, default=0),
last_seen = db.DateTimeProperty(required=True, auto_now_add=True),
created_date = db.DateTimeProperty(required=True, auto_now_add=True)
class PlayersHandler(webapp2.RequestHandler):
def get(self):
result = Player.get_by_key_name(self.request.get('name'))
if result:
result.last_seen = datetime.now()
result.number_requests += 1 # FAILS HERE
result.put()
self.response.out.write('{0}, {1}'.format(result.last_seen, result.number_requests))
Trace
Traceback (most recent call last):
File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2\webapp2.py", line 1536, in __call__
rv = self.handle_exception(request, response, e)
File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2\webapp2.py", line 1530, in __call__
rv = self.router.dispatch(request, response)
File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2\webapp2.py", line 1278, in default_dispatcher
return route.handler_adapter(request, response)
File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2\webapp2.py", line 1102, in __call__
return handler.dispatch()
File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2\webapp2.py", line 572, in dispatch
return self.handle_exception(e, self.app.debug)
File "C:\Program Files (x86)\Google\google_appengine\lib\webapp2\webapp2.py", line 570, in dispatch
return method(*args, **kwargs)
File "main.py", line 39, in get
result.number_requests += 1
TypeError: can only concatenate tuple (not "int") to tuple
The properties in your model have a comma (,) at the end. They shouldn’t. In python writing
is the same as if you’d put
which creates a tuple.