TypeError:<open file =“”'data',=“”mode =“”'r'=“”is =“”not =“”json =“”serializable =“”

时间:2017-04-11 15:49:10

标签: python python-2.7 apache-storm

1 个答案:

答案 0 :(得分:0)

错误消息告诉所有内容。您试图序列化文件对象,而不是从文件读取的数据。您需要将读取的数据放入变量并发送。

class SimSpout(storm.Spout):
  def initialize(self, conf, context):
     self.f = 'data'
     self._conf = conf
     self._context = context
     self._offset = 0
     storm.logInfo("Spout instance starting...")
  def nextTuple(self):
    with open(self.f) as l:
      data = l.readlines()[self._offset]
      storm.logInfo("Emiting %s" % data)
      storm.emit([data])
      self._offset = self._offset + 1
SimSpout().run()