[Django]-Pyapns Fault 500: 'Connection to the APNS server could not be made

5👍

I had the same problem – it’s frustrating, because it can make the connection, the .pem file is likely improperly formatted.

Follow this fantastic step-by-step set of directions to generate the correct final .pem file:

http://blog.serverdensity.com/2009/07/10/how-to-build-an-apple-push-notification-provider-server-tutorial/

Also, set passwords when you’re exporting the cert and key from Keychain – I know it says you can do without, but I found setting the password to something random on export from Keychain, then following the final openssl rsa ... step to remove said password before concatenating the files helped fix the problems I was having.

I can’t speak to an absolute certainty, but for me, it was the .pem files, which generated the exact error messages you’re receiving above.

The final .pem file is text and should be formatted a little something like this (note that the info here is randomly generated and I repeated lines a lot):

https://gist.github.com/58f79e1cd811f62bf011

Hope this helps 🙂

2👍

I got this error while using pyapns…tried all the answers in this post and many others…nothing helped…so just decided to use a different library (https://github.com/djacobs/PyAPNs). Worked first time!

1👍

I’m having the same problem but this seems to have solved it for me. Apparently, my .pem still had a password, and that was the problem. So here I’ll describe how to generate a .pem with no password.

This blog post outlines how to get the 2 ‘.pem’ files (Cert and Key) you need and how to concatenate them. http://www.raywenderlich.com/3443/apple-push-notification-services-tutorial-part-12. (You can use a password to generate the .pem files for now – we will strip the password later).

Here’s 2 commands that will help you check if your 2 .pem files are ok. This first command just checks if you can connect to APNS.

$ telnet gateway.sandbox.push.apple.com 2195

This second command will check if your .pem files are ok – you’ll get a bunch of output, if you’ve connected successfully. If successful, and if you input some random text, it will disconnect. If you can’t connect, it’ll output an error message.

$ openssl s_client -connect gateway.sandbox.push.apple.com:2195 -cert PushChatCert.pem -key PushChatKey.pem

After you have your concatenated .pem, you have to get rid of its password for pyapns. To do this, use this command on your .pem.

$ openssl rsa -in haspassword.pem -out nopassword.pem

And that should be it. I hope this helps!

1👍

I had this error as well and in my case it resulted from having a “.” in my app_id

0👍

I had this error as well and in my case it is because I missed out python-epoll library as mentioned in the documentation.

I think it is also helpful to check the twistd.log in your current directory

👤chitak

Leave a comment