I am trying to send FCM push notifications from a local Python script using the Firebase Admin SDK. My goal is to fetch FCM tokens from a Firestore collection (admins) and send a simple push notification to them using a service account key. My script is able to successfully authenticate with the service account key and can successfully connect to and read from my Firestore database. I can see it fetching the correct FCM tokens in the logs. However, the script consistently fails with an HTTP 404 error when it tries to execute the messaging.send_multicast(message) call. It seems unable to find the FCM server endpoint, even though other Firebase services are working correctly. Here is the complete Python script I am using for testing, now updated to log the request payload before sending: import firebase_admin import json from firebase_admin import credentials, firestore, messaging # Initialize Firebase Admin SDK. try: # NOTE: The service account key file is in the same directory cred = credentials.Certificate("teman-ngadu-firebase-adminsdk-fbsvc-f7340df514.json") firebase_admin.initialize_app(cred) print(">>> Firebase Admin SDK initialized successfully.") except Exception as e: print(f"XXX SDK initialization failed: {e}") exit() def send_notification_to_admins(): """ Fetches admin FCM tokens and sends a push notification. """ try: db = firestore.client() print(">>> Successfully connected to Firestore.") admins_ref = db.collection("admins").stream() tokens = [] print(">>> Fetching admin tokens...") for admin_doc in admins_ref: admin_data = admin_doc.to_dict() if admin_data and admin_data.get("fcmToken"): token = admin_data.get("fcmToken") tokens.append(token) print(f" - Found token: ...{token[-10:]}") if not tokens: print("XXX No FCM tokens found in the 'admins' collection. Exiting.") return print(f">>> Total of {len(tokens)} tokens found.") message = messaging.MulticastMessage( notification=messaging.Notification( title="Test Notification from Python Script!", body="If you received this, the connection to FCM was successful.", ), tokens=tokens, ) # Log the payload that will be sent for debugging payload_for_log = { "notification": { "title": "Test Notification from Python Script!", "body": "If you received this, the connection to FCM was successful.", }, "tokens": tokens, } print("\n>>> Preparing to send the following payload:") print(json.dumps(payload_for_log, indent=2)) print("----------------------------------------\n") print(">>> Sending notification...") response = messaging.send_multicast(message) if response.success_count > 0: print(f">>> Successfully sent {response.success_count} notifications!") except Exception as e: print(f"XXX An error occurred while running the function: {e}") if __name__ == "__main__": send_notification_to_admins() I expected the script to print a success message and for the push notification to arrive on the targeted devices. Instead, the script fails with an HTTP 404 error. This is the new, complete output including the logged payload: >>> Firebase Admin SDK initialized successfully. >>> Successfully connected to Firestore. >>> Fetching admin tokens... - Found token: ...doFkxS1hVg - Found token: ...PejHhqZxVA - Found token: ...UJUV8vzEEA >>> Total of 3 tokens found. >>> Preparing to send the following payload: { "notification": { "title": "Test Notification from Python Script!", "body": "If you received this, the connection to FCM was successful." }, "tokens": [ "fS7W0W5tSJmRUA8lqTBmfm:APA91bGVodhUQqJ9LejihFbSjghkPy5GpEWncIe8qlzrfIDPQYF1nOPl_nCgVie6VZF-68WBNxIlXxFHSAzdenabes0bONNzR_0XSP5AXk9OAdoFkxS1hVg", "fXynHsMURYyeH8cQc-K9id:APA91bFViHoqoS0NuSzR8dhgMn2uj4HJNJV8OP-b4pUnxjlJxsmXT8uOSI0_beKVAFevmyj7SvhBEMds6Yjawh3fxih3aJrwm-hUcTulVGrAlPejHhqZxVA", "f6y2moUNRjiT9dxSBJnfxr:APA91bFZ13Es3vLsV_HNXOtSCjTOPvKu8JsrLUhh_aM7kZFpqcA698EdSOMYN5QMVMMyQxNqAYPAAo5ourQUNlBmsbexy90zQaPb5xE3rPz8yUJUV8vzEEA" ] } ---------------------------------------- >>> Sending notification... XXX An error occurred while running the function: Unexpected HTTP response with status: 404; body: <!DOCTYPE html> <html lang=en> <meta charset=utf-8> <meta name=viewport content="initial-scale=1, minimum-scale=1, width=device-width"> <title>Error 404 (Not Found)!!1</title> ... (rest of HTML error page) ... <p><b>404.</b> <ins>That’s an error.</ins> <p>The requested URL <code>/batch</code> was not found on this server. <ins>That’s all we know.</ins> Here is what I have tried to solve this: Enabled FCM API: I have double- and triple-checked in my Google Cloud Console that the Firebase Cloud Messaging API is enabled. I have also tried disabling it, waiting, and re-enabling it. Checked Permissions: The service account I am using has the Editor role for the project, which should be more than enough permission. Tested with Cloud Functions: I first encountered this error in a Cloud Function (both background-triggered and callable). I wrote this local Python script specifically to isolate the problem, but the error is exactly the same. Tested Tokens Manually: I have confirmed the FCM tokens themselves are valid. I can successfully send a test notification to these exact tokens using the Firebase Console's Cloud Messaging composer. It seems there is a project-level configuration issue preventing any server-side SDK from finding the FCM endpoint, but I am out of ideas. What could be causing this? Continue reading...