流框架错误



我正在尝试设置基本feed:

from stream_framework.feeds.redis import RedisFeed
class PinFeed(RedisFeed):
    key_format = 'feed:normal:%(user_id)s'
class UserPinFeed(PinFeed):
    key_format = 'feed:user:%(user_id)s'

feed = UserPinFeed(13)

但是,当我在添加单个活动后运行feed[:2]时,我会遇到此错误:

<ipython-input-25-41b7cd0d0d8c> in <module>()
----> 1 feed[:2]
/Users/home/venv/lib/python2.7/site-packages/stream_framework/feeds/base.pyc in __getitem__(self, k)
    303         try:
    304             results = self.get_activity_slice(
--> 305                 start, bound)
    306         except StopIteration:
    307             # There's nothing left, even though the bound is higher.
/Users/home/venv/lib/python2.7/site-packages/stream_framework/feeds/base.pyc in get_activity_slice(self, start, stop, rehydrate)
    354         print 'line 350'
    355         if self.needs_hydration(activities) and rehydrate:
--> 356             activities = self.hydrate_activities(activities)
    357         return activities
    358
/Users/home/venv/lib/python2.7/site-packages/stream_framework/feeds/base.pyc in hydrate_activities(self, activities)
    332         activity_data = {a.serialization_id: a for a in activity_list}
    333         print activity_data
--> 334         return [activity.get_hydrated(activity_data) for activity in activities]
    335
    336     def needs_hydration(self, activities):
/Users/home/venv/lib/python2.7/site-packages/stream_framework/activity.pyc in get_hydrated(self, activities)
     42
     43         '''
---> 44         activity = activities[int(self.serialization_id)]
     45         activity.dehydrated = False
     46         return activity
KeyError: 14929294667170000000001005L

我能够打印出[<stream_framework.activity.DehydratedActivity object at 0x10e114e90>][u'14929294667170000000001005']

有什么线索会导致这是什么?

这里存在类型不匹配的,在KeyError堆栈跟踪中显示的密钥与[u'14929294667170000000001005']

的打印表示形式之间

u'14929294667170000000001005'是一个Unicode字符串而14929294667170000000001005Llong类型整数。

键本身或您尝试使用的值,因为查找键必须更改,因此类型相同。请注意,带有或不带有L后缀的INT(表示long类型(可以从Python dict检索值。一个简单的演示:

>>> D = {14929294667170000000001005 : 'some value'}
>>> D[14929294667170000000001005]
'some value'
>>> D[14929294667170000000001005L]
'some value'

相关内容

  • 没有找到相关文章

最新更新