我已经在 pythonanywhere 的在线 python 服务器中安装了 pyrebase,当我收到来自 HTTP 客户端的请求时,我正在尝试使用流来检查子节点处的更改值。这是代码:
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 ""
pyrebase 的 get、post 和 patch 功能运行良好。知道为什么流不起作用吗?