3

I'm new to Firebase and I'm using the Pyrebase library. I was able to authenticate successfully and I'm able to get data. The issue is, when I print the data out, it's printing out the reference object, not the actual data itself.

I've been searching online for a while and everything I've seen, shows that my code is correct. I've tried the .each method, but that doesn't work.

results = db.child("test").get()
for i in results.each():
    print(i)

What I'm expecting is the data from my json to be displayed. What's happening, is the object reference is being passed, but that doesn't do me any good.

What the results are:

<pyrebase.pyrebase.Pyre object at 0x03B48A90>
<pyrebase.pyrebase.Pyre object at 0x03B488D0>
<pyrebase.pyrebase.Pyre object at 0x03B48590>

Process finished with exit code 0
a stone arachnid
  • 1,272
  • 1
  • 15
  • 27
killsburydouboy
  • 309
  • 1
  • 3
  • 14

2 Answers2

1

I reread the documentation and I believe I have a fix for it. Original Code:

for i in results.each():
    print(i)

Fix:

for result in results.each():
    print(result.val())

I was missing the .val() during my print statement.

killsburydouboy
  • 309
  • 1
  • 3
  • 14
0

You can use the following piece of code to access the key as well as value of the data.

results = db.child("test").get()

for item in results.each():
    print(item.key(), item.val())