dennis dennis - 1 month ago 9
Python Question

Pyapns Fault 500: 'Connection to the APNS server could not be made

Hi 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 cant get it to connect to the apple push notification server.

The service are mostly done this is the last thing that a what 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
telnet gateway.sandbox.push.apple.com 2195
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.

Answer

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 :)