Reputation: 13
installed pyfcm using : pip install pyfcm
from pyfcm import FCMNotification
ImportError: cannot import name 'FCMNotification'
getting this import error in both python2.7 and python3.5
Upvotes: 0
Views: 3421
Reputation: 11
To install this package with conda
run one of the following:
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
Upvotes: 1
Reputation: 13
After many tries i resolved this error by just restarting my system.
and here is my working code which triggers notification when a value change in 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)
hope this will help you out :)
Upvotes: 0