0

I'm trying to run my own auth checking with google app engine, and using code from this question:

I wrote a method in my endpoints server class like this:

 @classmethod
 def get_user_from_headers(cls):
    try:
        user_id = cls.request_state.headers['user-id']
        api_token = cls.request_state.headers['api-token']
        user = ndb.Key(User, int(user_id)).get()
        if user.apiToken != api_token:
            raise endpoints.UnauthorizedException('Api Token error')
        return user
    except:
        raise endpoints.UnauthorizedException('no user found')

elsewhere:

@endpoints.method(containers.AddMemberToEventContainer, messages.EventsMessage, path='events/{event_id}',
                  http_method='POST', name='add.member.to.event')
def add_member_to_event(self, req):
    user = self.get_user_from_headers()

The user class just extends the ndb.Model i.e. User(ndb.Model)

But when I get the user returned, python thows an error saying the user is not callable with the line user = self.get_user_from_headers()

Inside of the get headers method, I tried logging just before returning the user, and it shows up in the logs as expected. How can I pass back the user from this method to the endpoints method?

edit: Here's the actual error:

TypeError: 'User' object is not callable
Community
  • 1
  • 1
Asitaka
  • 355
  • 1
  • 2
  • 14

1 Answers1

0

I don't know if this is the correct way to do it, but I created a Callable Model class and extended that:

class CallableModel(ndb.Model)
    def __call__(self):
        return self

Now it works....

Asitaka
  • 355
  • 1
  • 2
  • 14