Hi,

I am developing an Google app engine application using Moderator API
in python. I am able to retrieve the submissions. I am having an
authentication problem. My code runs locally without any problem but
when I deploy it in Google app engine launcher. It shows the following
error:


'NoneType' object has no attribute 'user_id'
Traceback (most recent call last):
  File "/base/python_runtime/python_lib/versions/1/google/appengine/
ext/webapp/__init__.py", line 700, in __call__
    handler.get(*groups)
  File "/base/data/home/apps/ktbookstore/3.351197542995528852/
retrieve_list_unique.py", line 107, in get
    f = Flow.get_by_key_name(user.user_id())
AttributeError: 'NoneType' object has no attribute 'user_id'

My code is:

import gflags
import httplib2
import logging
import pprint
import sys
import os
import cgi
import pickle

from apiclient.discovery import build
from oauth2client.file import Storage
from oauth2client.client import AccessTokenRefreshError
from oauth2client.client import OAuth2WebServerFlow
from oauth2client.tools import run
from google.appengine.ext import webapp
from google.appengine.ext.webapp import template
from google.appengine.ext.webapp.util import run_wsgi_app
from google.appengine.ext import db
from google.appengine.api import users
from oauth2client.appengine import CredentialsProperty
from oauth2client.appengine import StorageByKeyName
from google.appengine.ext.webapp.util import login_required
from google.appengine.api import memcache
from oauth2client.appengine import FlowProperty

FLAGS = gflags.FLAGS

FLOW = OAuth2WebServerFlow(
    client_id='My client id',
    client_secret='my client_secret',
    scope='https://www.example.com/oauth2callback',
    user_agent='moderator-cmdline-sample/1.0')


gflags.DEFINE_enum('logging_level', 'ERROR',['DEBUG', 'INFO',
'WARNING', 'ERROR', 'CRITICAL'],'Set the level of logging detail.')

class Flow(db.Model):   # FlowThreeLegged could also be stored in
memcache.
    flow = FlowProperty()

class Credentials(db.Model):
  credentials = CredentialsProperty()

class ModPage(webapp.RequestHandler):
  def get(self):
    # Let the gflags module process the command-line arguments

    service = build("moderator", "v1", developerKey='my developer
key')


class voteUpdate(webapp.RequestHandler):
  def get(self):
      user = users.get_current_user()
      logging.info(user)
      f = Flow.get_by_key_name(user.user_id())
      if f:
        credentials = f.flow.step2_exchange(self.request.params)
        c = Credentials(key_name=user.user_id(),
credentials=credentials)
        c.put()
        f.delete()
        self.redirect("/")
      else:
        pass
      user = users.get_current_user()
      c = Credentials.get_by_key_name(user.user_id())
      if c:
        http = httplib2.Http()
        http = c.credentials.authorize(http)
      else:
        flow = FlowThreeLegged(
                              consumer_key='',
                              consumer_secret='anonymous',
                              user_agent='google-api-client-python-
moderator-webapp/1.0',
                              domain='anonymous',
                              scope='https://www.googleapis.com/auth/
moderator',
                              xoauth_displayname='Example Web App')
      authorize_url = flow.step1_get_authorize_url(STEP2_URI)
      f = Flow(key_name=user.user_id(), flow=flow)
      f.put()
      self.redirect(authorize_url)



      service = build("moderator", "v1", http=http,developerKey='my
developer key')


      minus=self.request.get("Minus")
      if minus=="":
        self.response.out.write("plus")
        #code which will increment plus vote counter by 1
      else:
        self.response.out.write("minus")
        #code which will increment minus vote counter by 1




application = webapp.WSGIApplication([
  ('/', ModPage),('/vote',voteUpdate)
], debug=True)

def main():
   run_wsgi_app(application)


if __name__ == '__main__':
  main()

Please help me in finding the solution.

-- 
You received this message because you are subscribed to the Google Groups 
"Google App Engine" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/google-appengine?hl=en.

Reply via email to