firebase-admin-python icon indicating copy to clipboard operation
firebase-admin-python copied to clipboard

Requested entity was not found

Open oluwaseunladeinde opened this issue 8 years ago • 36 comments

Send messages

  • Trying to send a message to an android device with its registration token.
  • I get a 404 all the time
    • requests.exceptions.HTTPError: 404 Client Error: Not Found for url: https://fcm.googleapis.com/v1/projects/project-id/messages:send
  • firebase_admin.messaging.ApiCallError: Requested entity was not found.

Need help urgently

  • Operating System version: Windows 10
  • Firebase SDK version: firebase-admin-python
  • Library version: Python 3
  • Firebase Product: messaging

A Cue

Steps to reproduce:

Get the token from a registered android device and tried sending message to the same device but kept getting a 404 entity requested not found. I am confused at what entity it is referring to. . I was wondering if I had to save the device token on my firebase db?

oluwaseunladeinde avatar Jul 15 '18 22:07 oluwaseunladeinde

The SDK is not detecting your project ID. How did you initialize the SDK? Share the code please.

hiranya911 avatar Jul 17 '18 05:07 hiranya911

from firebase_admin import credentials, initialize_app, delete_app, auth, db, get_app,
messaging

cred = credentials.Certificate('filename.json') default_app = initialize_app(cred) message = messaging.Message(data={'note': '2864974004'}, token='',) response = messaging.send(message)

@hiranya911 I suspect that is the case. But the filename.json was generated from my serviceaccount from the Google API Console. SO I am not sure how the Project ID is not recognized.

oluwaseunladeinde avatar Jul 18 '18 18:07 oluwaseunladeinde

Did you edit the following error message in any way before posting? I see the string project-id in the URL, which is not correct:

requests.exceptions.HTTPError: 404 Client Error: Not Found for url: https://fcm.googleapis.com/v1/projects/project-id/messages:send

If this is indeed the error you receive, then that's the issue.

hiranya911 avatar Jul 18 '18 18:07 hiranya911

I actually did. It was my attempt to mask my project id. Not sure if it was safe to make that public. @hiranya911

oluwaseunladeinde avatar Jul 19 '18 23:07 oluwaseunladeinde

Ok, in that case my initial guess was wrong. The SDK does indeed correctly pick up the project ID. Try downloading a service account from Firebase console, and give this another try. I'm thinking this has something to do with how your service account json was obtained.

hiranya911 avatar Jul 20 '18 00:07 hiranya911

Hi @hiranya911 I get an entirely new error with a new service account generated from the Firebase Console twice. I have enabled Firebase Cloud Messaging API but nothing works.

** raise HTTPError(http_error_msg, response=self) requests.exceptions.HTTPError: 403 Client Error: Forbidden for url: https://fcm.googleapis.com/v1/projects/project-id/messages:send

** raise ApiCallError(code, msg, error) firebase_admin.messaging.ApiCallError: The caller does not have permission

Do you have a sample codebase that works that I can use as a guide. At this point, its difficult to tell whether it is my code or there are some pieces in the setup I have missed. The Python code on the documentation has not helped much.

Thanks in advance.

oluwaseunladeinde avatar Jul 23 '18 00:07 oluwaseunladeinde

The issue doesn't reproduce to me. And since this is the only report we have received on this issue, it's most likely a problem with your environment and project set up. Try capturing the full response payload sent by the back-end server. You can access this via the detail property of the ApiCallError.

err.detail.response.json()

hiranya911 avatar Jul 23 '18 23:07 hiranya911

I had the same error as your initial one and it turned out that my device ID changed and I was still using the old ID. If anyone sees that error in the future it might be worth double checking that you have the correct device token.

joshimbriani avatar Aug 06 '18 21:08 joshimbriani

I'm closing this as there aren't enough details to investigate this further. Please let us know if somebody finds something new related to this.

hiranya911 avatar Aug 17 '18 21:08 hiranya911

I also faced the same issue if device no longer exists it show me the error like that i actually send bulk notification having device ids inside an array and loop through it when any device id no longer exist it break my code i want to handle and continue to next device id { "message": "Client error: POST https://fcm.googleapis.com/v1/projects/internationalfriendspusher/messages:send resulted in a 404 Not Found response:\n{\n "error": {\n "code": 404,\n "message": "Requested entity was not found.",\n "status": "NOT_FOUND",\n "detail (truncated...)\n", "exception": "Kreait\Firebase\Exception\Messaging\NotFound", "file": "/var/www/vhosts/lvps87-230-85-233.dedicated.hosteurope.de/pusherang/MainApp/vendor/kreait/firebase-php/src/Firebase/Exception/MessagingException.php", "line": 76 }

Syednazirhussain avatar Sep 24 '18 12:09 Syednazirhussain

Got an interesting case, we recieved "Requested entity was not found." error for some old device ids, but notification was still delivered to the device

vsukhin avatar Oct 16 '18 15:10 vsukhin

Got same error when sending notifications

zardilior avatar Mar 28 '19 19:03 zardilior

I can confirm I get the same error as well when delivering notifications and most of them are being delivered.

(I am using the nodejs library though, but I'm posting here as the issue is related and this might just be a server side thing)

Shahor avatar Apr 02 '19 17:04 Shahor

I had this error when sending notifications to devices that did not contain the app any longer

zardilior avatar Apr 09 '19 15:04 zardilior

Or where the app had an error

zardilior avatar Apr 09 '19 15:04 zardilior

Hi, might be related. Had the same issue. But with me it was the setup of the target to deploy to multiple sites that was setup incorrectly. Added to the hosting - the target URL instead of the firebase hosting identifier.

firebase target:apply hosting

Instead of:

firebase target:apply hosting

After running deploy - it worked then.

EricCronje avatar Apr 18 '19 07:04 EricCronje

Got the same issue when trying to send a notification. The app is installed and push token also has been recently updated.

{ Error: Requested entity was not found.
    at FirebaseMessagingError.FirebaseError [as constructor] (/srv/node_modules/firebase-admin/lib/utils/error.js:42:28)
    at FirebaseMessagingError.PrefixedFirebaseError [as constructor] (/srv/node_modules/firebase-admin/lib/utils/error.js:88:28)
    at new FirebaseMessagingError (/srv/node_modules/firebase-admin/lib/utils/error.js:253:16)
    at Function.FirebaseMessagingError.fromServerError (/srv/node_modules/firebase-admin/lib/utils/error.js:283:16)
    at Object.createFirebaseError (/srv/node_modules/firebase-admin/lib/messaging/messaging-errors.js:34:47)
    at /srv/node_modules/firebase-admin/lib/messaging/messaging-api-request.js:76:42
    at <anonymous>
    at process._tickDomainCallback (internal/process/next_tick.js:229:7)
  errorInfo: 
   { code: 'messaging/registration-token-not-registered',
     message: 'Requested entity was not found.' },
  codePrefix: 'messaging' }

pocheshire avatar May 15 '19 08:05 pocheshire

I'm experiencing this issue too. Push notifications tokens are reported as invalid after the user uninstalls the app and Firebase Admin throws the error.

requests.exceptions.HTTPError: 404 Client Error: Not Found for url: https://fcm.googleapis.com/v1/projects/fabrictools-de669/messages:send

   File "/usr/local/lib/python3.6/dist-packages/flask/app.py", line 1832, in full_dispatch_request
     rv = self.dispatch_request()
   File "/usr/local/lib/python3.6/dist-packages/flask/app.py", line 1818, in dispatch_request
     return self.view_functions[rule.endpoint](**req.view_args)
   File "/app/nocd/app.py", line 1413, in moderator_push_notification_send
     utils.send_notifications(ios_messages, fcm_messages)
   File "/app/nocd/utils.py", line 428, in send_notifications
     send_fcm_notifications(fcm_notifications)
   File "/app/nocd/utils.py", line 444, in send_fcm_notifications
     response = messaging.send(notification)
   File "/usr/local/lib/python3.6/dist-packages/firebase_admin/messaging.py", line 100, in send
     return _get_messaging_service(app).send(message, dry_run)
   File "/usr/local/lib/python3.6/dist-packages/firebase_admin/messaging.py", line 371, in send
     self._handle_fcm_error(error)
   File "/usr/local/lib/python3.6/dist-packages/firebase_admin/messaging.py", line 472, in _handle_fcm_error
     raise ApiCallError(code, msg, error)
 firebase_admin.messaging.ApiCallError: Requested entity was not found.

This issue should probably be reopened.

rayliverified avatar Jun 07 '19 16:06 rayliverified

Push notifications tokens are reported as invalid after the user uninstalls the app and Firebase Admin throws the error.

But isn't that the intended behavior?

hiranya911 avatar Jun 07 '19 17:06 hiranya911

Throwing an exception crashes the app and causes subsequent notifications to not be sent. Is there a recommended way to handle this situation? Perhaps catch the exception and match an error code?

rayliverified avatar Jun 07 '19 17:06 rayliverified