How to print out all values in dictionary using for loop

Question:

Hello I am trying to print out all values of an object from Firebase in Python but instead , it prints only the first value

@app.route(‘/get_racer’,methods=[‘GET’] )

data = db.(“child”).get()

for x in data.each():
      print(x.val() )
Asked By: Kevin Fiadzeawu

||

Answers:

  1. Check if the data actually contains multiple values by printing the length of the data object:
data = db.child("child").get()
print(len(data.each())) # should print the number of objects in data
  1. Check if the Firebase query is returning the correct data by printing the entire data object:
data = db.child("child").get()
print(data.val()) # should print the entire object from Firebase
  1. Check if there are any errors being thrown by Firebase or Python by wrapping the code in a try-except block:
try:
   data = db.child("child").get()
   for x in data.each():
      print(x.val())
except Exception as e:
   print("Error: ", e)

Answered By: Scalobe