首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在尝试使用TypeError-merge时获得错误“NoneType:'NoneType‘对象不可迭代”

在尝试使用TypeError-merge时获得错误“NoneType:'NoneType‘对象不可迭代”
EN

Stack Overflow用户
提问于 2014-07-30 06:55:56
回答 2查看 2.1K关注 0票数 2

我试图使用窃窃私语合并2个wsp文件。他们有相同的保留策略,其中一个只是有旧的数据比另一个。

当我运行whisper-merge oldfile.wsp newfile.wsp时,我会得到这个错误

代码语言:javascript
复制
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

有什么想法吗?

以下是这两个文件的元数据输出:

  • "from_file“http://sprunge.us/dBHC
  • "to_file“http://sprunge.us/eIVG
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2014-07-30 07:21:29

来自whisper.py的片段

代码语言:javascript
复制
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 (至少显式地):

代码语言:javascript
复制
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
    ...
票数 1
EN

Stack Overflow用户

发布于 2014-07-31 00:32:36

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

代码语言:javascript
复制
fromTime = int(time.time()) - headerFrom['maxRetention']

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

代码语言:javascript
复制
for archive in archives: # this line already exists
  fromTime = int(time.time()) - archive['retention'] # add this line
票数 7
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/25030467

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档