代码之家  ›  专栏  ›  技术社区  ›  hillu

如何恢复损坏的python“cPickle”转储?

  •  3
  • hillu  · 技术社区  · 16 年前

    rss2email 用于将多个RSS提要转换为邮件,以便于使用。也就是说,我

    Traceback (most recent call last):
      File "/usr/share/rss2email/rss2email.py", line 740, in <module>
        elif action == "list": list()
      File "/usr/share/rss2email/rss2email.py", line 681, in list
        feeds, feedfileObject = load(lock=0)
      File "/usr/share/rss2email/rss2email.py", line 422, in load
        feeds = pickle.load(feedfileObject)
    TypeError: ("'str' object is not callable", 'sxOYAAuyzSx0WqN3BVPjE+6pgPU', ((2009, 3, 19, 1, 19, 31, 3, 78, 0), {}))
    

    我能够从这个回溯中构建的唯一有用的事实是,文件 ~/.rss2email/feeds.dat cPickle

    我甚至找到了包含该内容的行 'sxOYAAuyzSx0WqN3BVPjE+6pgPU' 上面提到的巨型字符串(>12MB) feeds.dat

    Python版本是Debian/unstable系统上的2.5.4。

    编辑

    Feed rss2email.py

    #!/usr/bin/python
    
    import sys
    # import pickle
    import cPickle as pickle
    sys.path.insert(0,"/usr/share/rss2email")
    from rss2email import Feed
    
    feedfile = open("feeds.dat", 'rb')
    feeds = pickle.load(feedfile)
    

    “普通”pickle变体产生以下回溯:

    Traceback (most recent call last):
      File "./r2e-rescue.py", line 8, in <module>
        feeds = pickle.load(feedfile)
      File "/usr/lib/python2.5/pickle.py", line 1370, in load
        return Unpickler(file).load()
      File "/usr/lib/python2.5/pickle.py", line 858, in load
        dispatch[key](self)
      File "/usr/lib/python2.5/pickle.py", line 1133, in load_reduce
        value = func(*args)
    TypeError: 'str' object is not callable
    

    r2e

    Traceback (most recent call last):
      File "./r2e-rescue.py", line 10, in <module>
        feeds = pickle.load(feedfile)
    TypeError: ("'str' object is not callable", 'sxOYAAuyzSx0WqN3BVPjE+6pgPU', ((2009, 3, 19, 1, 19, 31, 3, 78, 0), {}))
    

    Feed.__setstate__

              u'http:/com/news.ars/post/20080924-everyone-declares-victory-in-smutfree-wireless-broadband-test.html': u'http:/com/news.ars/post/20080924-everyone-declares-victory-in-smutfree-wireless-broadband-test.html'},
     'to': None,
     'url': 'http://arstechnica.com/'}
    Traceback (most recent call last):
      File "./r2e-rescue.py", line 23, in ?
        feeds = pickle.load(feedfile)
    TypeError: ("'str' object is not callable", 'sxOYAAuyzSx0WqN3BVPjE+6pgPU', ((2009, 3, 19, 1, 19, 31, 3, 78, 0), {}))
    

    4 回复  |  直到 16 年前
        1
  •  5
  •   HoldOffHunger Lux    5 年前

    我如何解决我的问题

    pickle.py

    pickle 格式是,我出去端口的一部分 pickle.py Perl。一对夫妇 关于Python是值得的。另外,我仍然觉得更多 使用Perl(和调试代码)比使用Python更舒服。

    类和对象是迄今为止唯一一个需要更多关注的问题 而不仅仅是习语的简单翻译。结果是一个模块 Pickle::Parse 经过一点抛光后

    Python::Serialise::Pickle

    解析、转换数据、检测流中的实际错误

    基于 泡菜::Parse feeds.dat 文件。 一条与以下内容惊人相似的错误消息 pickle.py 的原件 错误消息:

    Can't use string ("sxOYAAuyzSx0WqN3BVPjE+6pgPU") as a subroutine
    ref while "strict refs" in use at lib/Pickle/Parse.pm line 489,
    <STDIN> line 187102.
    

    哈!现在我们很可能已经到了实际数据 它坏了。

    事实证明,以下序列的第一行是错误的:

    g7724
    ((I2009
    I3
    I19
    I1
    I19
    I31
    I3
    I78
    I0
    t(dtRp62457
    

    “备忘录”中的7724位置指向该字符串 "sxOYAAuyzSx0WqN3BVPjE+6pgPU" .根据早期的类似记录 time.struct_time 相反。所有后来的记录都共享了这个错误的指针。用一个简单

    我偶然发现了错误的来源,这很讽刺 当数据流死亡时。

    结论

    1. 我会离开 rss2email 只要我有时间
    2. pickle.py 需要更多有意义的错误消息来告诉用户 关于数据流的位置(而不是其自身的位置 代码)出错的地方。
    3. pickle.py
        2
  •  3
  •   Peter Gibson    16 年前

    类似于(从您的主目录):

    import cPickle, pickle
    f = open('.rss2email/feeds.dat', 'r')
    obj1 = cPickle.load(f)
    obj2 = pickle.load(f)
    

    皮特

    编辑:cPickle和pickle给出相同错误的事实表明feeds.dat文件是问题所在。可能是rss2email版本之间的Feed类发生了变化,正如Ubuntu bug J.F.Sebastian链接中所建议的那样。

        3
  •  2
  •   Ned Batchelder    16 年前
        4
  •  2
  •   jfs    16 年前
    1. 'sxOYAAuyzSx0WqN3BVPjE+6pgPU'
    2. python -c "import pickle; pickle.load(open('feeds.dat'))"
      

    编辑:

    'tail -2'

    from pprint import pprint
    def setstate(self, dict_):
        pprint(dict_, stream=sys.stderr, depth=None)
        self.__dict__.update(dict_)
    Feed.__setstate__ = setstate
    

    如果上述内容没有产生有趣的输出,请使用一般的故障排除策略:

    确认 'feeds.dat'

    • 备份 ~/.rss2email 目录
    • 添加几个饲料,添加饲料直到 大小大于当前值。运行一些测试。
    • 在现有的rss2email安装上尝试新的feed.dat

    r2e bails out with TypeError Ubuntu上的错误。