3

I am trying to get my django app to send a push notification to an iOS device running the iOS app of this service. I am trying to use pyapns to send the notifications. But I can't get it to connect to the Apple push notification server.

The service is mostly done this is the last thing that I want to get to work before I step out of beta. You can visit http://pagemove.se/ to read about the app.

Here is the log:

Traceback (most recent call last): File "", line 1, in File "/usr/local/lib/python2.7/dist-packages/pyapns/client.py", line 75, in wrapper return func(*a, **kw) File "/usr/local/lib/python2.7/dist-packages/pyapns/client.py", line 67, in wrapper return func(*a, **kw) File "/usr/local/lib/python2.7/dist-packages/pyapns/client.py", line 97, in notify return _xmlrpc_thread(*f_args) File "/usr/local/lib/python2.7/dist-packages/pyapns/client.py", line 127, in _xmlrpc_thread errback(e) File "/usr/local/lib/python2.7/dist-packages/pyapns/client.py", line 65, in errback_wrapper errback(e) # not an instance of UnknownAppID - nothing we can do here File "/usr/local/lib/python2.7/dist-packages/pyapns/client.py", line 55, in errback raise e xmlrpclib.Fault:

Has anybody had this problem? Can it be same thing with the .pem file? or the setup of the ubuntu-server? Can i have forgotten to open some ports in the router?

Edit

I did a test to se if the ports for apns is open. I did

telnet gateway.sandbox.push.apple.com 2195

and got

Trying 17.149.34.65...
Connected to gateway.sandbox.push-apple.com.akadns.net.
Escape character is '^]'.

I do think that the server and router are setup correct.

5 Answers 5

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
  • Hi thank you for your answer. I did chanch to another python wrapper to make it work and now all is working good.
    – dennis
    May 3, 2012 at 20:10
  • I got the same errors from pyapns when my .pem files had a password set. Fixed using openssl command from link in answer. Sep 6, 2012 at 15:09
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
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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.