firebase TypeError:__ init __()缺少2个必需的位置参数:'session'和'build_headers'

时间:2017-10-04 20:43:27

标签: python firebase-realtime-database

我刚开始学习python和firebase。我想在firebase中为一个节点设置一个监听器。节点在

https://database.firebaseio.com/NSN

所以我正在阅读本教程

https://github.com/firebase/EventSource-Examples/blob/master/python/chat.py

根据上面的教程我想出了这段代码

URL ="https://database.firebaseio.com/Missing NSN.json"


class ClosableSSEClient(SSEClient):
    """
    Hack in some closing functionality on top of the SSEClient
    """

    def __init__(self, *args, **kwargs):
        self.should_connect = True
        super(ClosableSSEClient, self).__init__(*args, **kwargs)

    def _connect(self):
        if self.should_connect:
            super(ClosableSSEClient, self)._connect()
        else:
            raise StopIteration()

    def close(self):
        self.should_connect = False
        self.retry = 0
        # HACK: dig through the sseclient library to the requests library down to the underlying socket.
        # then close that to raise an exception to get out of streaming. I should probably file an issue w/ the
        # requests library to make this easier
        self.resp.raw._fp.fp._sock.shutdown(socket.SHUT_RDWR)
        self.resp.raw._fp.fp._sock.close()


    self.sse = ClosableSSEClient(URL)
    for msg in self.sse:
        msg_data = json.loads(msg.data)
        if msg_data is None:    # keep-alives
           continue
           path = msg_data['path']
           data = msg_data['data']
           if path == '/':
           # initial update
              if data:
                  keys = data.keys()
                  keys.sort()
                  print(keys)
                  for k in keys:
                      self.message_queue.put(data[k])
           else:
               self.message_queue.put(data)

当我运行此脚本时,我收到此错误

>>  Traceback (most recent call last):
File "NSNListener.py", line 96, in <module>
self.sse = ClosableSSEClient(URL)
File "NSNListener.py", line 78, in __init__
super(ClosableSSEClient, self).__init__(*args, **kwargs)
TypeError: __init__() missing 2 required positional arguments: 'session' and 'build_headers'   
TypeError: __init__() missing 2 required positional arguments: 'session' and 'build_headers'

我该如何解决这个问题?

0 个答案:

没有答案