[英]Firebase RTDB Listener doesn't work with FastAPI
Here is my code related to Firebase RTDB Listener:这是我与 Firebase RTDB 侦听器相关的代码:
import firebase_admin
from firebase_admin import credentials
from firebase_admin import db
class FirebaseConfig:
reference = None
listenerRegistration = None
def __init__(self):
cred = credentials.Certificate("path_to_credentials.json")
firebase_admin.initialize_app(
cred,
{'databaseURL': 'database_url'}
)
self.reference = db.reference("Users")
self.listenerRegistration = self.reference.listen(self.userListener)
def userListener(self, event):
print("Listener Started.")
try:
print(event.data)
updateData() # A function to update our local database
except Exception as e:
raise Exception("Listener Error" + str(e))
def stopListening(self):
print("Closing Listener")
self.listenerRegistration.close()
The problem I am facing right now is that this listener doesn't work.我现在面临的问题是这个监听器不起作用。 The print statements don't print anything.
打印语句不打印任何内容。 I think this is because of FastAPI.
我认为这是因为 FastAPI。 Is there any way that I can make it work?
有什么办法可以让它工作吗?
If they cannot work well together, do you have any alternative solutions for the same?如果它们不能很好地协同工作,您是否有其他替代解决方案?
I think it might have probably been because I was using port 80 for my uvicorn server.我想这可能是因为我的 uvicorn 服务器使用了端口 80。 I changed it and it worked.
我改变了它并且它起作用了。 This is the most probable reason.
这是最可能的原因。 Cannot say for sure.
不能肯定地说。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.