T
T
tadej2016-01-26 13:26:49
Django
tadej, 2016-01-26 13:26:49

How to connect the APNS certificate correctly?

There is a function to send messages

PUSH_NOTIFICATIONS_SETTINGS = {
        "APNS_CERTIFICATE": os.path.join(PROJECT_ROOT, 'rss/CorruptionDevPushCer.p12'),
}

from rss.settings import PUSH_NOTIFICATIONS_SETTINGS

def send_message(data, kwargs):
    device_apns_ids = [d.device_id for d in UserDevice.objects.filter(client=client, active=True, device=2).all()]
    cert_file = PUSH_NOTIFICATIONS_SETTINGS['APNS_CERTIFICATE']
    apns_enhanced = APNs(use_sandbox=True, cert_file=cert_file, enhanced=True)
    payload = Payload(alert=kwargs['pid'], sound="default", badge=1)
    frame = Frame()
    identifier = 1
    expiry = time.time() + 3600
    priority = 10
    for device_apns_id in device_apns_ids:
        device_apns_id = str(device_apns_id)
        frame.add_item(device_apns_id, payload, identifier, expiry, priority)

    apns_responce = apns_enhanced.gateway_server.send_notification_multiple(frame)

The result of the work
[Errno 336265218] _ssl.c:355: error:140B0002:SSL routines:SSL_CTX_use_PrivateKey_file:system lib

Where is the mistake?
Path to certificate aplication/rss

Answer the question

In order to leave comments, you need to log in

1 answer(s)
T
tadej, 2016-01-26
@tadej

Thank you all
Here is an example that normally shows how to do it
https://github.com/klen/klen.github.io/tree/master...
An error arose, because I did not write the relative paths to the certificate correctly

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question