You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Receiving invalid-argument error code instead of invalid-registration-token when sending push notification #187
Firebase SDK version: firebase-admin 2.12.0 on Python 3.5.2
Firebase Product: messaging
Describe the problem
Hi there,
When I send a push notification using messaging.send with an invalid token I expect an invalid-registration-token error but and invalid-argument error is raised. The invalid token is generated adding an extra char at the end of the token. Is this the expected behavior? With the legacy HTTP API an invalid token error was returned.
Thanks
Relevant Code:
from firebase_admin import messaging
app = firebase_admin.get_app()
token = VALID_TOKEN+"a"
try:
result = messaging.send(
message=messaging.Message(
notification=messaging.Notification(
title="Push",
body="message"
),
token=push_id
),
app=app)
except messaging.ApiCallError as error:
assert error.code == "invalid-registration-token"
This is just the way the new FCM API reports errors. Here's the full response received from the server:
{
"error": {
"code": 400,
"message": "Request contains an invalid argument.",
"status": "INVALID_ARGUMENT",
"details": [
{
"@type": "type.googleapis.com/google.firebase.fcm.v1.FcmError",
"errorCode": "INVALID_ARGUMENT"
},
{
"@type": "type.googleapis.com/google.rpc.BadRequest",
"fieldViolations": [
{
"field": "message.token",
"description": "Invalid registration token"
}
]
},
{
"@type": "type.googleapis.com/google.rpc.BadRequest",
"fieldViolations": [
{
"field": "message.token",
"description": "The registration token is not a valid FCM registration token"
}
]
},
{
"@type": "type.googleapis.com/google.rpc.DebugInfo",
"detail": "[ORIGINAL ERROR] generic::invalid_argument: bad registration id data: foo-bar\ncom.google.apps.framework.request.StatusException: \u003ceye3 title='INVALID_ARGUMENT'/\u003e generic::INVALID_ARGUMENT: bad registration id data: foo-bar [google.rpc.error_details_ext] { details { type_url: \"type.googleapis.com/google.firebase.fcm.v1.FcmError\" value: \"\\010\\001\" } details { type_url: \"type.googleapis.com/google.rpc.BadRequest\" value: \"\\n+\\n\\rmessage.token\\022\\032Invalid registration token\" } details { type_url: \"type.googleapis.com/google.rpc.BadRequest\" value: \"\\nM\\n\\rmessage.token\\022\u003cThe registration token is not a valid FCM registration token\" } }"
}
]
}
}
If you want you can access this response, and parse it to get to the exact field violations:
try:
messaging.send(msg)
except messaging.ApiCallError as ex:
response = ex.detail.response # This is a requests.Response object
response_data = response.text # Read the response as a string
Activity
hiranya911 commentedon Aug 3, 2018
This is just the way the new FCM API reports errors. Here's the full response received from the server:
If you want you can access this response, and parse it to get to the exact field violations: