2017-09-10 1 views
0

Ich verwende den folgenden Code, um Daten von Firebase auf Raspberry Pi abzurufen, aber es zeigt folgenden Fehler. Ich kann jedoch Daten ohne Authentifizierung abrufen.'FirebaseApplication' Objekt hat kein Attribut 'Authentifizierung'

from firebase.firebase import FirebaseApplication 
    from firebase.firebase import FirebaseAuthentication 
    firebase = firebase.FirebaseApplication('https://myapp.firebaseio.com/', 
    authentication =None) 
    authentication = firebase.Authentication('secretkey', 
    '[email protected]', extra={'id': 123}) 
    firebase.authentication = authentication 
    print (authentication.extra) 
    user = authentication.get_user() 
    print (user.firebase_auth_token) 
    result = firebase.get('/messages', None) 

es zeigt folgende Fehler

Traceback (most recent call last):

File "/home/pi/code/dataauth.py", line 7, in authentication = firebase.Authentication('secretkey', '[email protected]', extra={'id': 123}) AttributeError: 'FirebaseApplication' object has no attribute 'Authentication'

Ich bin in der Lage Daten ohne Authentifizierung zu holen dh Regeln auf true setzen, durch den Code folgenden

from firebase.firebase import FirebaseApplication 
firebase = firebase.FirebaseApplication('https://myapp.firebaseio.com/', 
None) 
result = firebase.get('/messages', None) 

Antwort

0

Ich nehme an, Sie python verwenden Firebase, die ein wenig veraltet ist und für lange Zeit nicht aktualisiert wurde. Ich habe versucht, Ihr Problem zu beheben, gefunden Lösung für Ihr Problem, aber ein Problem mit der Authentifizierung tritt immer noch auf.

Code:

from firebase.firebase import FirebaseApplication 
from firebase.firebase import FirebaseAuthentication 
DSN = config['databaseURL'] # 'https://myapp.firebaseio.com/' 
SECRET = config['userPass'] # 'secretkey' 
EMAIL =config['userEmail'] # '[email protected]' 

authentication = FirebaseAuthentication(SECRET,EMAIL, True, True) 
firebase = FirebaseApplication(DSN, authentication) 

firebase.get('/messages', None) 

Ich würde vorschlagen, in pyrebase zu bewegen, die mehr aktualisiert wird und wie ich habe Werke gerade überprüft.

https://github.com/thisbejim/Pyrebase

Code, der funktioniert für mich:

import pyrebase 
config = { 
    'apiKey': "YYY", 
    'authDomain': "XXXXXXXX.firebaseapp.com", 
    'databaseURL': "https://XXXXXXXX.firebaseio.com", 
    'projectId': "XXXXXXXX", 
    'storageBucket': "XXXXXXXX.appspot.com", 
    'messagingSenderId': "ZZZ", 
} 
firebase = pyrebase.initialize_app(config) 

userEmail = 'youremailadresthatyouaddedtofirebasedatabaseauthenticatedusers' 
userPass = 'yourpasswordsetupforthisemail' 

auth = firebase.auth() 

# Log the user in 
user = auth.sign_in_with_email_and_password(userEmail, userPass) 

# Get a reference to the database service 
db = firebase.database() 

# data to save 
data = { 
      "name": "Mortimer 'Morty' Smith" 
      } 

# Pass the user's idToken to the push method 
results = db.child("test").push(data, user['idToken']) 
print results 
results = db.child("test").get(user['idToken']) 
print results.val() 
Verwandte Themen