Skip to content

DatabaseReference.listen(callback) not working in firebase-admin 4.0.0 #426

Closed
@Malik056

Description

@Malik056

[READ] Step 1: Are you in the right place?

  • For issues or feature requests related to the code in this repository
    file a Github issue.
    • If this is a feature request make sure the issue title starts with "FR:".
  • For general technical questions, post a question on StackOverflow
    with the firebase tag.
  • For general Firebase discussion, use the firebase-talk
    google group.
  • For help troubleshooting your application that does not fall under one
    of the above categories, reach out to the personalized
    Firebase support channel.

[REQUIRED] Step 2: Describe your environment

  • Operating System version: macOS Catalina version 10.15.3
  • Firebase SDK version: N/A
  • Library version: 4.0.0
  • Firebase Product: realtime database

[REQUIRED] Step 3: Describe the problem

I am writing a python script that listen to the changes in firebase realtime database. The DatabaseReference.listen was working fine with firebase-admin-3.2.1 but when i updated the version of firebase-admin-3.2.1 to firebase-admin-4.0.0, the DatabaseReference.listen stopped working. It raises following exception:

Traceback (most recent call last):
  File "/Users/apple/PycharmProjects/LatestSoundTranslation/main.py", line 105, in <module>
    ref.listen(on_value_change)
  File "/Users/apple/PycharmProjects/LatestSoundTranslation/venv/lib/python3.7/site-packages/firebase_admin/db.py", line 376, in listen
    session = _sseclient.KeepAuthSession(self._client.credential)
AttributeError: '_Client' object has no attribute 'credential'

Steps to reproduce:

Install latest firebase-admin package using pip install firebase-admin==4.0.0

cred = credentials.Certificate('./google-services.json')
default_app = firebase_admin.initialize_app(cred, {
    'databaseURL': 'https://your-project-id.firebaseio.com/'
})
ref = db.reference().child("any_node")
ref.listen(on_value_change)

Relevant Code:

def on_value_change(response):
    print(response)

cred = credentials.Certificate('./project39172648d8c7.json')
default_app = firebase_admin.initialize_app(cred, {
    'databaseURL': 'https://speechtranslate-40b4d.firebaseio.com/'
})
ref = db.reference().child("any_node')
ref.listen(on_value_change)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions