Sending Django push notification to APNs gets protocol error

635 Views Asked by At

In my server I have django-push-notifications==1.6.0 and there is this strange error:

Sending a push to FCM with package version 1.6.0 works fine, but with APNs sending a push I get this error (Traceback):

apns.objects.get(pk=26).send_message('hello')

No handlers could be found for logger "apns2.client"
Traceback (most recent call last):
      File "<console>", line 1, in <module>
      File "/virtpy/myapp/local/lib/python2.7/site-packages/push_notifications/models.py", line 167, in send_message
        **kwargs
      File "/virtpy/myapp/local/lib/python2.7/site-packages/push_notifications/apns.py", line 113, in apns_send_message
        certfile=certfile, **kwargs
      File "/virtpy/myapp/local/lib/python2.7/site-packages/push_notifications/apns.py", line 94, in _apns_send
        **notification_kwargs
      File "/virtpy/myapp/local/lib/python2.7/site-packages/apns2/client.py", line 53, in send_notification
        stream_id = self.send_notification_async(token_hex, notification, topic, priority, expiration, collapse_id)
      File "/virtpy/myapp/local/lib/python2.7/site-packages/apns2/client.py", line 78, in send_notification_async
        stream_id = self._connection.request('POST', url, json_payload, headers)
      File "/virtpy/myapp/local/lib/python2.7/site-packages/hyper/http20/connection.py", line 281, in request
        self.endheaders(message_body=body, final=True, stream_id=stream_id)
      File "/virtpy/myapp/local/lib/python2.7/site-packages/hyper/http20/connection.py", line 555, in endheaders
        stream.send_headers(headers_only)
      File "/virtpy/myapp/local/lib/python2.7/site-packages/hyper/http20/stream.py", line 98, in send_headers
        conn.send_headers(self.stream_id, headers, end_stream)
      File "/virtpy/myapp/local/lib/python2.7/site-packages/h2/connection.py", line 839, in send_headers
        self.state_machine.process_input(ConnectionInputs.SEND_HEADERS)
      File "/virtpy/myapp/local/lib/python2.7/site-packages/h2/connection.py", line 246, in process_input
        "Invalid input %s in state %s" % (input_, old_state)
    ProtocolError: Invalid input ConnectionInputs.SEND_HEADERS in state ConnectionState.CLOSED

And now if I downgrade the package to django-push-notifications==1.4.1 APNs works fine and FCM won't work now getting this error:

Invalid field name(s) for model GCMDevice: 'cloud_message_type'.

Settings in server:

PUSH_NOTIFICATIONS_SETTINGS = {
    "FCM_API_KEY": "[MY_FCM_KEY]",
    "APNS_CERTIFICATE": os.path.join(BASE_DIR, push_certificate),
    "APNS_TOPIC": "com.company.myapp",
    "GCM_ERROR_TIMEOUT": 60,
}

How I create devices:

device, created = GCMDevice.objects.get_or_create(
                registration_id=android_token,
                defaults={'user': user,
                          'cloud_message_type': 'FCM'}
            )

device, created = APNSDevice.objects.get_or_create(
                registration_id=ios_token,
                defaults={'user': user}
            )

Any idea how to get both running?

1

There are 1 best solutions below

0
On

Updating packages from the server (ubuntu, general update) fixed the problem. And now I can run 1.6.0 django-push-notifications