FCM – send push notifications using Python

What is FCM ?

FCM – Firebase Cloud Messaging is a cross-platform ( Android, iOS and Chrome ) messaging solution that lets you reliably deliver messages at no cost. FCM is best suited if you want to send push notification to your app which you built to run on Android and iOS. The advantage you get is you don’t have to separately deal with GCM (Google Cloud Messaging deprecated now) and Apple’s APNS. You hand over your notification message to FCM and FCM takes care of communicating with apple’s APNS and Android messaging servers to reliably deliver those messages.

Using FCM we can send message to single device or multiple devices. There are two different types of messages, notification and data. Notification messages include JSON keys that are understood and interpreted by phone’s operating system. If you want to include customized app specific JSON keys use data message. You can combine both notification and data JSON objects in single message. You can also send messages with different priority.

Note : – You need to set
priority to
high if you want phone to wake up and show notification on screen

Sending message with Python

We can use PyFCM to send messages via FCM. PyFCM is good for synchronous ( blocking ) python. We will discuss non-blocking option in next paragraph.

With help of fcm console and this token-id, you can send test-notifications to your device. If you want to send notifications from your server using pyFCM, you need to deliver this token-id to server. Ideally at time of authentication with your server, you can do it.

hi
i get this error HTTPSConnectionPool(host=’fcm.googleapis.com’, port=443): Max retries exceeded with url: /fcm/send (Caused by ProxyError(‘Cannot connect to proxy.’, NewConnectionError(‘: Failed to establish a new connection: [WinError 10061] No connection could be made because the target machine actively refused it’,)))