jazzband / django-push-notifications

Send push notifications to mobile devices through GCM or APNS in Django.
MIT License
2.26k stars 613 forks source link

hyper.http20.exceptions.StreamResetError: Stream forcefully closed #408

Open Archideus opened 7 years ago

Archideus commented 7 years ago

APNs max_concurrent_streams too high (4294967297), resorting to default maximum (1000) Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python3.5/site-packages/push_notifications/models.py", line 129, in send_message certfile=certfile, kwargs File "/usr/local/lib/python3.5/site-packages/push_notifications/apns.py", line 137, in apns_send_bulk_message certfile=certfile, kwargs File "/usr/local/lib/python3.5/site-packages/push_notifications/apns.py", line 87, in _apns_send **notification_kwargs File "/usr/local/lib/python3.5/site-packages/apns2/client.py", line 122, in send_notification_batch priority, expiration, collapse_id) File "/usr/local/lib/python3.5/site-packages/apns2/client.py", line 78, in send_notification_async stream_id = self._connection.request('POST', url, json_payload, headers) File "/usr/local/lib/python3.5/site-packages/hyper/http20/connection.py", line 281, in request self.endheaders(message_body=body, final=True, stream_id=stream_id) File "/usr/local/lib/python3.5/site-packages/hyper/http20/connection.py", line 546, in endheaders stream = self._get_stream(stream_id) File "/usr/local/lib/python3.5/site-packages/hyper/http20/connection.py", line 289, in _get_stream raise StreamResetError("Stream forcefully closed") hyper.http20.exceptions.StreamResetError: Stream forcefully closed

Kianoosh76 commented 7 years ago

+1 The internal implementation for APNS was working as well, but when I've upgraded the package this error raises every time!

jksimoniii commented 6 years ago

+1

Using v1.5.0

Kianoosh76 commented 6 years ago

I've opened an issue in the source package page and now the problem is fixed!

umair151 commented 6 years ago

Facing the same error, what was the solution?

jeffreybrowning commented 6 years ago

Faced the same error. As @Kianoosh76 reported, it is a problem with use_sandbox. The APNSClient in send_batch_message is not being initialized with the proper arg for use_sandbox.

The solution was to set USE_SANDBOX at every bundle dict in django settings like so. I only needed it in my dev app, so I used a simple check to set it:

for bundle_id in ('com....dev', 'com...dev-alt',
                  'com...staging', 'com...beta'):

    PUSH_NOTIFICATIONS_SETTINGS['APPLICATIONS'][bundle_id] = {                   
        'PLATFORM': 'APNS',
        'CERTIFICATE': get_cert_path(bundle_id),
        'TOPIC': bundle_id,
        'USE_SANDBOX': bundle_id == 'com...dev',
    }
martin-xia commented 6 years ago

Got the same problem "Stream forcefully closed" here, using production cert and the following settings:

PUSH_NOTIFICATIONS_SETTINGS = { "APNS_TOPIC": Bundle id, "UPDATE_ON_DUPLICATE_REG_ID": True, "APNS_USE_SANDBOX": False }

And I'm passing the production cert file when calling send_message.

martin-xia commented 6 years ago

Fixed, turns out something is wrong with the generated production cert's subject

elcolie commented 5 years ago

I use development cert and my app also in the development. I need to set settings.py DEBUG=True to solve this problem

andrewkoltsov commented 3 years ago

Got same issue: cert was generated for sandbox, solution: set APNS_USE_SANDBOX=True, but it may work on opposite way, if you are using production cert with APNS_USE_SANDBOX=True