将Django推送通知发送到APNs获取协议错误

时间:2018-06-29 07:54:56

标签: android django apple-push-notifications firebase-cloud-messaging django-push-notifications

在我的服务器中,我有django-push-notifications == 1.6.0,并且有一个奇怪的错误:

使用软件包版本1.6.0将推送发送到FCM可以正常工作,但是在APN发送推送的情况下,我收到此错误(跟踪):

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

现在,如果我将软件包降级为django-push-notifications == 1.4.1,则APN可以正常工作,并且FCM现在无法正常工作,并且出现此错误:

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

服务器中的设置:

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,
}

我如何创建设备:

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}
            )

有什么办法让两者同时运行吗?

1 个答案:

答案 0 :(得分:0)

从服务器更新软件包(ubuntu,常规更新)解决了该问题。现在我可以运行1.6.0 django-push-notifications

相关问题