self.user.user_id in the sample FB app throwing error

无人久伴 提交于 2019-12-11 11:48:00

问题


My FB app code had broken after a Facebook October 2012 Breaking Change and it got fixed by following a suggestion here: Picture property format using run with friends fb app

But interestingly, after fixing it, I am facing another issue in the same code (which I dont think existed earlier) I have searched through the Breaking Changes but this issue doesnt seem to be discussed there as well. Its complaining of user_id not being an attribute of self.user in this line: u'userIdOnServer': self.user.user_id if self.user else None. I have searched through forums etc. but couldnt find a clue.

Here's the error:

C:\Program Files\Google\google_appengine\google\appengine\ext\webapp\util.py in run_bare_wsgi_app(application=)

    114   env["wsgi.multithread"] = False
    115   env["wsgi.multiprocess"] = False
=>  116   result = application(env, _start_response)
    117   if result is not None:
    118     for data in result:

result undefined, application = <google.appengine.ext.webapp._webapp25.WSGIApplication object>, env = {'APPENGINE_RUNTIME': 'python', 'APPLICATION_ID': 'dev~app', 'AUTH_DOMAIN': 'gmail.com', 'CONTENT_LENGTH': '-1', 'CONTENT_TYPE': 'application/x-www-form-urlencoded', 'CURRENT_VERSION_ID': '1.1', 'GATEWAY_INTERFACE': 'CGI/1.1', 'HTTP_ACCEPT': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'HTTP_ACCEPT_CHARSET': 'ISO-8859-1,utf-8;q=0.7,*;q=0.3', 'HTTP_ACCEPT_LANGUAGE': 'en-US,en;q=0.8', ...}, global _start_response = <function _start_response>
 C:\Program Files\Google\google_appengine\google\appengine\ext\webapp\_webapp25.py in __call__(self=<google.appengine.ext.webapp._webapp25.WSGIApplication object>, environ={'APPENGINE_RUNTIME': 'python', 'APPLICATION_ID': 'dev~app', 'AUTH_DOMAIN': 'gmail.com', 'CONTENT_LENGTH': '-1', 'CONTENT_TYPE': 'application/x-www-form-urlencoded', 'CURRENT_VERSION_ID': '1.1', 'GATEWAY_INTERFACE': 'CGI/1.1', 'HTTP_ACCEPT': 'text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8', 'HTTP_ACCEPT_CHARSET': 'ISO-8859-1,utf-8;q=0.7,*;q=0.3', 'HTTP_ACCEPT_LANGUAGE': 'en-US,en;q=0.8', ...}, start_response=<function _start_response>)

    715           handler.error(501)
    716       except Exception, e:
=>  717         handler.handle_exception(e, self.__debug)
    718     else:
    719       response.set_status(404)

handler = <__main__.RecentRunsHandler object>, handler.handle_exception = <bound method RecentRunsHandler.handle_exception of <__main__.RecentRunsHandler object>>, e = AttributeError("**'dict' object has no attribute 'friends'",)**, self = <google.appengine.ext.webapp._webapp25.WSGIApplication object>, self.__debug undefined
 C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\ROOT\app\main.py in handle_exception(self=<__main__.RecentRunsHandler object>, ex=AttributeError("'dict' object has no attribute 'friends'",), debug_mode=True)
    228         self.log_exception(ex)
    229         self.render(u'error',
=>  230             trace=traceback.format_exc(), debug_mode=debug_mode)
    231 
    232     def log_exception(self, ex):

trace undefined, global traceback = <module 'traceback' from 'C:\Python27\lib\traceback.pyc'>, traceback.format_exc = <function format_exc>, debug_mode = True
 C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\ROOT\app\main.py in render(self=<__main__.RecentRunsHandler object>, name=u'error', **data={'debug_mode': True, 'trace': 'Traceback (most recent call last):\n File "C:\\Pr...eError: \'dict\' object has no attribute \'friends\'\n'})
    265             u'appId': conf.FACEBOOK_APP_ID,
    266             u'canvasName': conf.FACEBOOK_CANVAS_NAME,
=>  267             u'userIdOnServer': self.user.user_id if self.user else None,
    268         })
    269         data[u'logged_in_user'] = self.user

self = <__main__.RecentRunsHandler object>, self.user = {u'id': u'100003906996287', u'name': u'Sudhir Jain'}, self.user.user_id undefined, builtin None = None
**<type 'exceptions.AttributeError'>: 'dict' object has no attribute 'user_id' 
      args = ("'dict' object has no attribute 'user_id'",) 
      message = "'dict' object has no attribute 'user_id'"**

And here's the rendering code (I am building off of runwithfriends sample app):

def render(self, name, **data):
    """Render a template"""
    if not data:
        data = {}
    data[u'js_conf'] = json.dumps({
        u'appId': conf.FACEBOOK_APP_ID,
        u'canvasName': conf.FACEBOOK_CANVAS_NAME,
        u'userIdOnServer': self.user.user_id if self.user else None,
    })
    data[u'logged_in_user'] = self.user
    data[u'message'] = self.get_message()
    data[u'csrf_token'] = self.csrf_token
    data[u'canvas_name'] = conf.FACEBOOK_CANVAS_NAME
    self.response.out.write(template.render(
        os.path.join(
            os.path.dirname(__file__), 'templates', name + '.html'),
        data))

Sorry, if I missed providing any information but I would be glad to provide other info/error logs that you suggest. Thanks in advance.

来源:https://stackoverflow.com/questions/11815765/self-user-user-id-in-the-sample-fb-app-throwing-error

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!