Home > front end >  How to access firebase database without having 'Realtime Database'?
How to access firebase database without having 'Realtime Database'?

Time:01-13

Im trying to connect my python script to a Firebase database. Here is the code:

import firebase_admin
from firebase_admin import credentials, db
cred = credentials.Certificate("irebase-adminsdk-ofcmd-bwd7fbcz2c.json")
firebase_admin.initialize_app(cred, {'databaseURL':'https://company.firebaseio.com/'})

ref = db.reference('/users').get()

The ERROR Im facing looks like this:

requests.exceptions.HTTPError: 404 Client Error: Not Found for url: https://company.firebaseio.com/users.json

I did a lot of research and everyone says that I have to find the right URL in the 'Realtime Database' Section. I wonder if there is any way to access the Firebase db without having realtime one enabled.

CodePudding user response:

if you are looking to access the Firebase Database without having the realtime one enabled, you can try the Cloud Firestore which is a different database service provided by Firebase which doesn't require realtime database to be enabled but you may need to change the way you are accessing the data

import firebase_admin
from firebase_admin import credentials, firestore

# Initialize the Firebase Admin SDK with your service account credentials
cred = credentials.Certificate("firebase-adminsdk-that-cred-file.json")
firebase_admin.initialize_app(cred)

# Create a reference to the Firestore database
db = firestore.client()

# Read data from a specific document in the 'users' collection
doc_ref = db.collection('users').document('user1')
doc = doc_ref.get()

# Print the data from the document
print(doc.to_dict())
  • Related