【问题标题】:Getting the error "TypeError: 'NoneType' object is not iterable" when trying to use whisper-merge尝试使用耳语合并时出现错误“TypeError:'NoneType' object is not iterable”
【发布时间】:2014-07-30 06:55:56
【问题描述】:

我正在尝试使用 whisper-merge 合并 2 个 wsp 文件。它们具有相同的保留策略,一个只是比另一个拥有更旧的数据。

当我运行whisper-merge oldfile.wsp newfile.wsp 时出现此错误

Traceback (most recent call last):
  File "/usr/local/src/whisper-0.9.12/bin/whisper-merge.py", line 32, in <module>
    whisper.merge(path_from, path_to)
  File "/usr/local/lib/python2.7/dist-packages/whisper.py", line 821, in merge
    (timeInfo, values) = fetch(path_from, fromTime, untilTime)
TypeError: 'NoneType' object is not iterable

有什么想法吗?

这是 2 个文件的元数据输出:

【问题讨论】:

    标签: python graphite whisper


    【解决方案1】:

    对于包含多个档案的文件,whisper.py 中的第 812 行已损坏。 https://github.com/graphite-project/whisper/blob/0.9.12/whisper.py#L812

    fromTime = int(time.time()) - headerFrom['maxRetention']
    

    要修复,紧跟第 813 行,根据存档保留分配 fromTime。 https://github.com/graphite-project/whisper/blob/0.9.12/whisper.py#L813

    for archive in archives: # this line already exists
      fromTime = int(time.time()) - archive['retention'] # add this line
    

    【讨论】:

    • Jason,非常感谢您的建议,我今天在使用最新的稳定版 Graphite 时遇到了同样的问题。我认为您应该打开一个错误并建议对 Whisper 进行更改:)
    【解决方案2】:

    来自whisper.py的片段

    def fetch(path,fromTime,untilTime=None):
        """fetch(path,fromTime,untilTime=None)
    
        path is a string
        fromTime is an epoch time
        untilTime is also an epoch time, but defaults to now.
    
        Returns a tuple of (timeInfo, valueList)
        where timeInfo is itself a tuple of (fromTime, untilTime, step)
    
        Returns None if no data can be returned
        """
        fh = open(path,'rb')
        return file_fetch(fh, fromTime, untilTime)
    

    表明whisper.fetch() 正在返回None,这反过来(以及回溯中的最后一行)表明您的path_from 文件存在问题。
    再深入一点,whisper.file_fetch() 似乎有两个地方可以返回 None(至少明确表示):

    def file_fetch(fh, fromTime, untilTime):
        header = __readHeader(fh)
        now = int( time.time() )
        if untilTime is None:
            untilTime = now
        fromTime = int(fromTime)
        untilTime = int(untilTime)
    
        # Here we try and be flexible and return as much data as we can.
        # If the range of data is from too far in the past or fully in the future, we
        # return nothing
        if (fromTime > untilTime):
            raise InvalidTimeInterval("Invalid time interval: from time '%s' is after until time '%s'" % (fromTime, untilTime))
    
        oldestTime = now - header['maxRetention']
        # Range is in the future
        if fromTime > now:
            return None               # <== Here
        # Range is beyond retention
        if untilTime < oldestTime:
            return None               # <== ...and here
        ...
    

    【讨论】:

    • 这似乎很可能,但是从文件在石墨中渲染得很好
    • “from_file”的元数据sprunge.us/dBHC“to_file”的元数据sprunge.us/eIVG
    • None 可能来自两个明显的地方(可能有一些不明显的地方)。也许whisper.file_fetch() 中的几个调试prints 会缩小范围?
    猜你喜欢
    • 1970-01-01
    • 2022-08-18
    • 1970-01-01
    • 1970-01-01
    • 2017-10-14
    • 2017-08-01
    • 1970-01-01
    • 2022-08-04
    • 2022-12-15
    相关资源
    最近更新 更多