0

I am trying to connect to firebase using python, but when I try to run the code, it doesn't do anything, it just freezes. There is even no message or anything. My code:

import firebase_admin
from firebase_admin import db
from firebase_admin import credentials

cred = credentials.Certificate("service_key.json")
firebase_admin.initialize_app(cred, {
    'databaseURL': 'url'})
ref = db.reference('/')
ref.set({'Records': {'temp': 12, 'moisture': 25, 'CO2': 400}})

Can someone help me?

PS: when I run it using cmd, it runs perfectly.

Omar Yacop
  • 305
  • 1
  • 6

2 Answers2

0

What are you using to run the code? I just ran the same code in VS Code, and it worked fine. I used firebase-admin==6.0.0 version of the module and Python 3.9.

You could use the below code to figure out at which line the code gets stuck on your case.

import firebase_admin
from firebase_admin import db
from firebase_admin import credentials


print("Modules Loaded properly.")

cred = credentials.Certificate("service_key.json")
print("Creds Loaded Perfectly.")

firebase_admin.initialize_app(cred, {
    'databaseURL': 'url'})
print("App initialized properly.")

ref = db.reference('/')
print("DB reference created.")

ref.set({'Records': {'temp': 12, 'moisture': 25, 'CO2': 400}})
print("Data uploaded to db.")
Asif
  • 38
  • 3
0

I was using python 3.11 and it wasn't working so I switched to python 3.9.17 and it worked

  • 1
    As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Jul 03 '23 at 09:06