1

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?

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
lalitahuja
  • 105
  • 1
  • 4
  • 13
  • 1
    Add details of what you mean by "not working" – Glenn Mar 16 '20 at 10:51
  • @Glenn the function is working now but it is not printing on "server log" on the website instead it is printing on the console below the code editor on the website. Do you know how can I extract the values from the console? – lalitahuja Mar 16 '20 at 11:31
  • @Glenn Now the values are not even being printed on the console. – lalitahuja Mar 17 '20 at 16:05
  • If you're running that code in a web app, then your prints would be going to the error log, not a console. If you run that code in a console, nothing will happen because it has no way of receiving a request to run the code in handler. – Glenn Mar 17 '20 at 18:19

0 Answers0