安装 pyfcm 使用:pip install pyfcm
from pyfcm import FCMNotification
ImportError: cannot import name 'FCMNotification'
在 python2.7 和 python3.5 中都出现此导入错误
安装 pyfcm 使用:pip install pyfcm
from pyfcm import FCMNotification
ImportError: cannot import name 'FCMNotification'
在 python2.7 和 python3.5 中都出现此导入错误
经过多次尝试,我通过重新启动系统解决了这个错误。
这是我的工作代码,当 fire-base database 中的值更改时触发通知。
from pyfcm import FCMNotification
import pyrebase
push_service = FCMNotification(api_key="type server key here")
registration_id = "get this token from your app"
message_title = "Fire Alert"
message_body = "Fire Breakage dehradun"
config = {
"apiKey": "",
"authDomain": "",
"databaseURL": "",
"projectId": "",
"storageBucket": "",
"messagingSenderId": ""
};
firebase = pyrebase.initialize_app(config)
db = firebase.database()
def stream_handler(post):
print(post)
if (post['data'] is 1):
result = push_service.notify_single_device(registration_id=registration_id, message_title=message_title, message_body=message_body)
print (result)
my_stream = db.child("fire_sensor_status").stream(stream_handler, None)
希望这会帮助你:)
要安装此软件包,请conda
运行以下命令之一:
conda install -c conda-forge pyfim
conda install -c conda-forge/label/gcc7 pyfim
conda install -c conda-forge/label/cf201901 pyfim
conda install -c conda-forge/label/cf202003 pyfim