How to use Firebase Realtime Database stream using Pyrebase?

天涯浪子 提交于 2020-04-17 20:37:09

问题


I have installed pyrebase in an online python server which is pythonanywhere and I'm trying to use the stream to check the changed values at child node when I get a request from HTTP client. Here's the code:

from flask import Flask
from flask import request
import requests
import pyrebase

firebase = pyrebase.initialize_app(config)

app = Flask(__name__)


@app.route("/IOTSENSE/PINS", methods=["POST","GET"])
def handler():
    username = request.get_data()
    print(username.decode("utf-8"))
    username = username.decode("utf-8")
    result = [x.strip() for x in username.split(',')]
    print(result)

    db = firebase.database()
    users = db.child(device).child(child).get()
    print(users.val())

    def requestHandler(message):
        print(message["event"]) # put
        print(message["path"]) # /-K7yGTTEp7O549EzTYtI
        print(message["data"]) # {'title': 'Pyrebase', "body": "etc..."}

    my_stream = db.child("Data").stream(requestHandler)


    if r.status_code != 200:
     print( "Error:", r.status_code)
    return ""

The get, post and patch functions from pyrebase are working completely fine. Any idea why stream is not working?

来源:https://stackoverflow.com/questions/60677680/how-to-use-firebase-realtime-database-stream-using-pyrebase

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!