9

I am following the documentation given with the following pyAPNS library: https://github.com/djacobs/PyAPNs

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?

icodebuster
  • 8,890
  • 7
  • 62
  • 65
GangstaGraham
  • 8,865
  • 12
  • 42
  • 60

2 Answers2

8

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.

GangstaGraham
  • 8,865
  • 12
  • 42
  • 60
3

Just try with https://github.com/simonwhitaker/PyAPNs. Make sure you have configured you certificates correctly.

Refer Raywenderlich

icodebuster
  • 8,890
  • 7
  • 62
  • 65
  • Yeah, I used the Ray Wenderlich article to get it setup, and the link is a fork to the GitHub repo I was using. I will try to reconfigure the certificates, hopefully it works this time. – GangstaGraham May 14 '13 at 18:01
  • @GangstaGraham The links provided above was the links that I followed, just implemented APNS 2-3 weeks back, If I remember I had this issue because of wrong configuration of certificates. – icodebuster May 14 '13 at 18:32
  • Unfortunately, I have been going over the tutorial again and again, and I am using this repo, but I still get an error, this time it is different though, SSL_CTX_use_PrivateKey_file:PEM lib , also in the tutorial, we combine two PEM files into 1 file, but in the repo, we don't use the combined file, did you use the combined file? Your help is much appreciated. – GangstaGraham May 15 '13 at 04:19
  • Do You have APNS development certificate or production certificate? – icodebuster May 15 '13 at 04:22
  • Is it supposed to be the development certificate @icodebuster – GangstaGraham May 15 '13 at 04:26
  • Development certificate used when debugging and developing apps and production when releasing the app. – icodebuster May 15 '13 at 04:28
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/29960/discussion-between-icodebuster-and-gangstagraham) – icodebuster May 15 '13 at 04:28
  • @GangstaGraham Hey did you find a solution for APNS? – icodebuster May 15 '13 at 15:27
  • Yeah, it turns out that in Keychain Access, it asks for a password, so I thought I needed one, but if I just don't enter any password, it works fine. So the solution was: do not enter a password for the private key @icodebuster – GangstaGraham May 15 '13 at 20:55
  • 1
    Great never faced this problem before. Anyways good you found the solution. I used to give password and used `openssl pkcs12 -nocerts -out AppKey_pro.pem -in app.p12 -nodes` that worked for me. – icodebuster May 16 '13 at 05:12
  • @icodebuster I have created the certificate with passphrase but I dont know how to give it, I can't not to use the passphrase(client request); How can i dot it? – Armance Dec 02 '13 at 09:42
  • You either need to add the pass phrase or make the certificate without one – icodebuster Dec 02 '13 at 09:56
  • how can I add the )passphrase that's what I dont know how to do..`apns = APNs(use_sandbox=True, cert_file= certificate_file) payload = Payload(alert = message, sound="default", badge=1) apns.gateway_server.send_notification(token_hex, payload)` – Armance Dec 02 '13 at 11:00
  • @icodebuster I posted a question , can you help me plz http://stackoverflow.com/questions/20372128/iphone-push-notifications-passphrase-issue-pyapns – Armance Dec 04 '13 at 10:33