2

私はGoogleAppEngineで遊んでいて、値を1ずつインクリメントしようとしています(player.number_requests-以下のコードを参照)。ただし、そうすると、次のエラーが発生します。「TypeError:タプル( "int"ではない)のみをタプルに連結できます」。なぜこれが起こっているのか考えていますか?

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))

痕跡

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
4

1 に答える 1