我正在编辑 Runwithfriends FB 示例应用程序来构建我自己的一个。它工作正常,我在这里和那里做了一些改变。我休息了大约两周,但现在当我尝试访问该应用程序时,我收到了一个奇怪的 python 错误:
C:\Program Files\Apache Software Foundation\Tomcat 7.0\webapps\ROOT\app\main.py in init_facebook(self=< main .RecentRunsHandler object>) 316 user_id=facebook.user_id, friends=friends, 317 access_token=facebook。 access_token, name=me[u'name'], => 318 email=me.get(u'email'), picture=me[u'picture']) 319 user.put() 320 KeyError除外,例如:
<..一些部分被剪掉了..>
class 'google.appengine.api.datastore_errors.BadValueError'>: 属性图片必须是 str 或 unicode 实例,而不是 dict args = ('属性图片必须是 str 或 unicode 实例,而不是 dict',) message = '属性图片必须是 str 或 unicode 实例,而不是 dict'"
我知道这是一个非常通用的错误,但它指向以下代码。该代码一直存在,我从未接触过它。我真的不知道现在还能去哪里找 - 我已经彻底搜索但找不到线索。抱歉,如果这仍然太宽泛,但如果您能告诉我我可以提供哪些其他信息来调试它,我会很高兴:-(
def init_facebook(self):
"""Sets up the request specific Facebook and User instance"""
facebook = Facebook()
user = None
# initial facebook request comes in as a POST with a signed_request
if u'signed_request' in self.request.POST:
facebook.load_signed_request(self.request.get('signed_request'))
# we reset the method to GET because a request from facebook with a
# signed_request uses POST for security reasons, despite it
# actually being a GET. in webapp causes loss of request.POST data.
self.request.method = u'GET'
self.set_cookie(
'u', facebook.user_cookie, datetime.timedelta(minutes=1440))
elif 'u' in self.request.cookies:
facebook.load_signed_request(self.request.cookies.get('u'))
# try to load or create a user object
if facebook.user_id:
user = User.get_by_key_name(facebook.user_id)
if user:
# update stored access_token
if facebook.access_token and \
facebook.access_token != user.access_token:
user.access_token = facebook.access_token
user.put()
# refresh data if we failed in doing so after a realtime ping
if user.dirty:
user.refresh_data()
# restore stored access_token if necessary
if not facebook.access_token:
facebook.access_token = user.access_token
if not user and facebook.access_token:
me = facebook.api(u'/me', {u'fields': _USER_FIELDS})
try:
friends = [user[u'id'] for user in me[u'friends'][u'data']]
user = User(key_name=facebook.user_id,
user_id=facebook.user_id, friends=friends,
access_token=facebook.access_token, name=me[u'name'],
email=me.get(u'email'), picture=me[u'picture'])
user.put()
except KeyError, ex:
pass # ignore if can't get the minimum fields
self.facebook = facebook
self.user = user