当我尝试流式传输Firebase实时数据库时,我收到类型错误。这是我的代码的MRE。我一直在完美使用模块的其他功能,但是由于某些原因,当我尝试流式传输数据时,此错误始终出现。
from firebase import Firebase
import python_jwt as jwt
from gcloud import storage
from sseclient import SSEClient
from Crypto.PublicKey import RSA
from requests_toolbelt.adapters import appengine
config = {
"apiKey": "*******************************",
"authDomain": "*********************************",
"databaseURL": "*********************************",
"storageBucket": "********************************"
}
pythonfirebase = Firebase(config)
db = pythonfirebase.database()
def stream_handler(message):
print(message["event"]) # put
print(message["path"]) # /-K7yGTTEp7O549EzTYtI
print(message["data"]) # {'title': 'Pyrebase', "body": "etc..."}
my_stream = db.child("placements").stream(stream_handler)
这是完整的追溯
Exception in thread Thread-1:
Traceback (most recent call last):
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py", line 926, in _bootstrap_inner
self.run()
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "/Users/temitayoadefemi/PycharmProjects/test7/venv/lib/python3.7/site-packages/firebase/__init__.py", line 593, in start_stream
self.sse = ClosableSSEClient(self.url, session=self.make_session(), build_headers=self.build_headers)
File "/Users/temitayoadefemi/PycharmProjects/test7/venv/lib/python3.7/site-packages/firebase/__init__.py", line 554, in __init__
super(ClosableSSEClient, self).__init__(*args, **kwargs)
File "/Users/temitayoadefemi/PycharmProjects/test7/venv/lib/python3.7/site-packages/sseclient.py", line 48, in __init__
self._connect()
File "/Users/temitayoadefemi/PycharmProjects/test7/venv/lib/python3.7/site-packages/firebase/__init__.py", line 558, in _connect
super(ClosableSSEClient, self)._connect()
File "/Users/temitayoadefemi/PycharmProjects/test7/venv/lib/python3.7/site-packages/sseclient.py", line 56, in _connect
self.resp = requester.get(self.url, stream=True, **self.requests_kwargs)
File "/Users/temitayoadefemi/PycharmProjects/test7/venv/lib/python3.7/site-packages/requests/sessions.py", line 546, in get
return self.request('GET', url, **kwargs)
TypeError: request() got an unexpected keyword argument 'build_headers'
非常感谢您的帮助
答案 0 :(得分:1)
改为使用Firebase管理员sdk尝试
import firebase_admin
from firebase_admin import credentials
from firebase_admin import db
# Fetch the service account key JSON file contents
cred = credentials.Certificate(SERVICE_ACCOUNT_FILE)
# Initialize the app with a service account, granting admin privileges
firebase_admin.initialize_app(cred, {
'databaseURL': DATABASE_URL
})
# Get a database reference to our posts
ref = db.reference('messages')
def listener(event):
print(event.event_type) # can be 'put' or 'patch'
print(event.path) # relative to the reference, it seems
print(event.data) # new data at /reference/event.path. None if deleted
node = str(event.path).split('/')[-2] #you can slice the path according to your requirement
property = str(event.path).split('/')[-1]
value = event.data
if (node=='sala'):
#do something
""""""
elif (node=='ventilacion'):
#do something
""""""
else:
""""""
#do something else
# Read the data at the posts reference (this is a blocking operation)
# print(ref.get())
db.reference('/').listen(listener)