Skip to content

certificaton error when send push notification #64

@gb0519

Description

@gb0519

I use the following codes to send push notification with certification.
These codes are from "base usage" of the readme file (removed the key part)

import asyncio
from uuid import uuid4
from aioapns import APNs, NotificationRequest, PushType

async def run():
    apns_cert_client = APNs(
        client_cert='mycert.cer',
        use_sandbox=False,
    )
    request = NotificationRequest(
        device_token='<DEVICE_TOKEN>',
        message = {
            "aps": {
                "alert": "Hello from APNs",
                "badge": "1",
            }
        },
        notification_id=str(uuid4()),  # optional
        time_to_live=3,                # optional
        push_type=PushType.ALERT,      # optional
    )
    await apns_cert_client.send_notification(request)
   
loop = asyncio.get_event_loop()
loop.run_until_complete(run())

The certification I generated and downloaded from developer.apple.com is cer format,
if I use it directly as
client_cert='mycert.cer',
Then I will get error: ssl.SSLError: [SSL] PEM lib (_ssl.c:3900)

If I convert it to pem with code:
openssl x509 -inform der -in mycert.cer -out mycert.pem
Then change code to
client_cert='mycert.pem',
Then I will get error: ssl.SSLError: [SSL] PEM lib (_ssl.c:3921)

The full traceback:

Traceback (most recent call last):
  File "/root/PythonDoc/study/testAPNs.py", line 25, in <module>
    loop.run_until_complete(run())
  File "/usr/lib/python3.10/asyncio/base_events.py", line 649, in run_until_complete
    return future.result()
  File "/root/PythonDoc/study/testAPNs.py", line 6, in run
    apns_cert_client = APNs(
  File "/usr/local/lib/python3.10/dist-packages/aioapns/client.py", line 37, in __init__
    self.pool = APNsCertConnectionPool(
  File "/usr/local/lib/python3.10/dist-packages/aioapns/connection.py", line 455, in __init__
    self.ssl_context.load_cert_chain(cert_file)
ssl.SSLError: [SSL] PEM lib (_ssl.c:3921)

What should I do to get the right certification to make it work?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions