thisbejim / Pyrebase

A simple python wrapper for the Firebase API.
2.05k stars 525 forks source link

hello how do i know if it is connected to firebase #427

Closed paxsipornax closed 1 year ago

paxsipornax commented 1 year ago

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

AsifArmanRahman commented 1 year ago

@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")
paxsipornax commented 1 year ago

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

IGN-Styly commented 1 year ago

Issue Should already be closed!