向 APNs 发送 Django 推送通知会出现协议错误
Posted
技术标签:
【中文标题】向 APNs 发送 Django 推送通知会出现协议错误【英文标题】:Sending Django push notification to APNs gets protocol error 【发布时间】:2018-06-29 07:54:56 【问题描述】:在我的服务器中,我有 django-push-notifications==1.6.0 并且出现了这个奇怪的错误:
使用包版本 1.6.0 向 FCM 发送推送工作正常,但使用 APNs 发送推送时我收到此错误(回溯):
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 APNs 工作正常,而 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】:从服务器更新包(ubuntu,一般更新)解决了这个问题。现在我可以运行 1.6.0 django-push-notifications
【讨论】:
以上是关于向 APNs 发送 Django 推送通知会出现协议错误的主要内容,如果未能解决你的问题,请参考以下文章