Send Apple Notification Service A Message With Python


I am following the documentation given with the following pyAPNS library:

apns = APNs(use_sandbox=True, cert_file='ThePushCertificate.pem', key_file='ThePushKey.pem')
payload = Payload(alert="Checking if it works", sound="default", badge=1)
apns.gateway_server.send_notification(some_string, payload)

I am getting the following error:

SSLError: [Errno 1] _ssl.c:504: error:14094410:SSL routines:SSL3_READ_BYTES:sslv3 alert handshake failure

This error occurs on the last line of code displayed above.

What does this error mean? How do I fix this?

PS. I have been stuck on this for a couple of hours now.I found 1 similar question on here, but the answer did not really help me (for my situation). I will continue to try to figure out what's going wrong, I just felt it might be helpful if I get help from more advanced iOS / Python developers over here. Thanks!

After another day of trying to get it to work, I am stuck with a new error:

SSL_CTX_use_PrivateKey_file:PEM lib

I also went through the tutorial suggested in the answer below numerous times, but that did not help unfortunately. In the tutorial, a new combined PEM file is used, but with the repo's documentation, that file is not used, does anyone know how I should use that file?

12/2/2013 10:03:05 AM

Accepted Answer

The solution to my problem was that I was using a password for the private key.

Since Keychain Access explicitly asks for a password, I thought it was necessary. It is not.

Everything worked fine when I left the password blank.

5/15/2013 8:59:08 PM

Just try with Make sure you have configured you certificates correctly.

Refer Raywenderlich

Licensed under: CC-BY-SA with attribution
Not affiliated with: Stack Overflow