Invalid push token

#1

I’m following the expo guides for using push notifications. I’m able to successfully create a token using Notifications.getExponentPushTokenAsync(). I send that token to my Python server and try to create the notification on my phone using the send_push_message function outlined here: https://github.com/expo/exponent-server-sdk-python.
The response I get is
ValueError: Invalid Push token

I’ve Googled around a bit and haven’t found much…it looks like it could be some sort of SSL certificate issue. Anyone have some ideas on this?

EDIT: I’m using my Android phone for this. Relevant code below:

This is the code that is generating and sending the token from the phone to server:

async registerSocket(){

const { existingStatus } = await Permissions.getAsync(Permissions.REMOTE_NOTIFICATIONS);
let finalStatus = existingStatus

if (existingStatus !== 'granted') {
  const { status } = await Permissions.askAsync(Permissions.REMOTE_NOTIFICATIONS);
  finalStatus = status;
}

if (finalStatus !== 'granted') {
  return;
}

token = await Notifications.getExponentPushTokenAsync();
var payload = {
    action: 'register_socket',
    pushNotificationToken: token
}
var registerMessage = new Message(payload)
registerMessage.sign(this.keyManager.deviceID, this.keyManager.pkey).stringify()
this.sendMessage(registerMessage);

}

On the server side I’m calling this method when I receive the message (I’m able to receive the message and token from above without issue):

def send_push_message(token, message, extra=None):
try:
    response = PushClient().publish(
        PushMessage(to=token,
                    body=message,
                    data=extra))
except PushServerError as exc:
    rollbar.report_exc_info(
        extra_data={
            'token': token,
            'message': message,
            'extra': extra,
            'errors': exc.errors,
            'response_data': exc.response_data,
        })
    raise
except (ConnectionError, HTTPError) as exc:
    rollbar.report_exc_info(
        extra_data={'token': token, 'message': message, 'extra': extra})
    raise self.retry(exc=exc)

try:
    response.validate_response()
except DeviceNotRegisteredError:
    from notifications.models import PushToken
    PushToken.objects.filter(token=token).update(active=False)
except PushResponseError as exc:
    rollbar.report_exc_info(
        extra_data={
            'token': token,
            'message': message,
            'extra': extra,
            'push_response': exc.push_response._asdict(),
        })
    raise self.retry(exc=exc)
#2

hello! please paste relevant code here or share project if possible. also let us know what device you are using (simulator/emulator do not work!)

#4

Did you figure this out?

#5

It’s fixed. Stupid error…forgot to include ‘self’ as first argument in send_push_message

1 Like
#6

I also ran into a similar error. It was because the push token was type unicode. I had to convert it to a str.