Pyrebase icon indicating copy to clipboard operation
Pyrebase copied to clipboard

hello how do i know if it is connected to firebase

Open paxsipornax opened this issue 2 years ago • 3 comments

try:
firebase = pyrebase.initialize_app(firebaseConfig) auth = firebase.auth() db = firebase.database() print("connection") except: print("unconnection")

paxsipornax avatar Sep 10 '22 08:09 paxsipornax

@paxsipornax Generally using any service and getting a response back from the server would mean it's connected. All requests are checked for errors automatically so if any arises, it'll be handled on it's own to show the error.

Hopefully this snippet helps. The snippet uses firebase-rest-api, an up-to-date version of pyrebase and with feature's like Social login and Firestore.

from firebase import initialize_app

firebase = initialize_app(firebaseConfig)

db = firebase.database()

data = {"name": "Anthony 'Edward' Stark"}
db.child("test").child("users").child("Edward").set(data)

server_data = db.child("test").child("users").child("Edward").get().val()

if data == server_data:
    print("connection successful")
    db.child("test").remove()
else:
    print("connection unsuccessful")

AsifArmanRahman avatar Sep 10 '22 12:09 AsifArmanRahman

Thanks for information. a fix: server_data = db.child("test").child("users").child("Edward").get().val()

paxsipornax avatar Sep 12 '22 08:09 paxsipornax

Issue Should already be closed!

IGN-Styly avatar Oct 13 '22 23:10 IGN-Styly