Python 获取错误“;类型错误:';非类型';“对象不可编辑”;尝试使用耳语合并时

Python 获取错误“;类型错误:';非类型';“对象不可编辑”;尝试使用耳语合并时,python,graphite,whisper,Python,Graphite,Whisper,我正在尝试使用合并2wsp文件。他们有相同的保留策略,其中一个只保留比另一个旧的数据 当我运行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, pat

我正在尝试使用合并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
回溯(最近一次呼叫最后一次):
文件“/usr/local/src/whisper-0.9.12/bin/whisper merge.py”,第32行,在
合并(路径从,路径到)
文件“/usr/local/lib/python2.7/dist-packages/whisper.py”,第821行,合并中
(timeInfo,values)=获取(路径_from,fromTime,untime)
TypeError:“非类型”对象不可编辑
有什么想法吗

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

  • “从_文件”
  • “到_文件”

来自
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
,这反过来(以及回溯中的最后一行)表示文件中的
路径有问题。
再深入一点看,
whisper.file_fetch()
似乎有两个地方可以返回
None
(至少是明确的):

def file_fetch(fh、fromTime、untilTime):
页眉=\uuuu读取页眉(fh)
now=int(time.time())
如果untime为None:
untitime=现在
fromTime=int(fromTime)
untilTime=int(untilTime)
#在这里,我们尝试灵活地返回尽可能多的数据。
#如果数据范围在过去太远,或者在未来太远,我们
#一无所获
如果(从时间>到时间):
引发InvalidTimeInterval(“无效时间间隔:从时间'%s'在时间'%s'之后到时间'%s'”(从时间,到时间))
oldestTime=now-header['maxRetention']
#射程在未来
如果fromTime>now:

return None#对于包含多个存档的文件,whisper.py中的第812行已断开。

要修复此问题,请紧跟第813行,根据存档保留时间分配fromTime。


这似乎是可能的,但是from文件在“from_file”元数据的石墨数据中呈现良好,对于“to_file”,只有两个明显的地方
None
可能来自(可能有一些不明显的)。也许在
whisper.file_fetch()
中调试几次
print
s可以缩小范围?Jason,非常感谢你的建议,我今天在最新的stable Graphite中遇到了同样的问题。我认为您应该打开一个bug并建议更改为Whisper:)相关问题现在已经存在:
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
    ...
fromTime = int(time.time()) - headerFrom['maxRetention']
for archive in archives: # this line already exists
  fromTime = int(time.time()) - archive['retention'] # add this line