Flask apns - SysCallError: (-1, 'Unexpected EOF')

I am trying to use Flask-APNS, earlier I check that my ck.pem (cert and key in one file) is working on php server.

But every time I try to execute:

from apns import APNS
#apns = APNS(app, cert_file='ZivingCert.pem', key_file='ZivingKey.pem',passphrase='mypassphrase')
apns = APNS(app, cert_file='ck.pem', passphrase='mypassphrase')
apns.send_message(tokens=['fad71c0b27416f055bfb1617c8db4e55d1b98b412443e68fba65cfe59748b81a'], alert='hi world', extra={})

      

I am getting this error:

WARNING:apnsclient.backends.stdio:Failed to establish socket/SSL connection to ('gateway.sandbox.push.apple.com', 2195)

No handlers could be found for logger "apnsclient.backends.stdio"
    Traceback (most recent call last):

      File "/usr/local/Cellar/python/2.7.9/Frameworks/Python.framework/Versions/2.7/lib/python2.7/wsgiref/handlers.py", line 85, in run
        self.result = application(self.environ, self.start_response)
      File "/Users/Ricardo/Documents/python/openshift/scheduler_env/lib/python2.7/site-packages/flask/app.py", line 1836, in __call__
        return self.wsgi_app(environ, start_response)
      File "/Users/Ricardo/Documents/python/openshift/scheduler_env/lib/python2.7/site-packages/flask/app.py", line 1820, in wsgi_app
        response = self.make_response(self.handle_exception(e))
      File "/Users/Ricardo/Documents/python/openshift/scheduler_env/lib/python2.7/site-packages/flask_restful/__init__.py", line 263, in error_router
        return original_handler(e)
      File "/Users/Ricardo/Documents/python/openshift/scheduler_env/lib/python2.7/site-packages/flask/app.py", line 1403, in handle_exception
        reraise(exc_type, exc_value, tb)
      File "/Users/Ricardo/Documents/python/openshift/scheduler_env/lib/python2.7/site-packages/flask_restful/__init__.py", line 260, in error_router
        return self.handle_error(e)
      File "/Users/Ricardo/Documents/python/openshift/scheduler_env/lib/python2.7/site-packages/flask/app.py", line 1817, in wsgi_app
        response = self.full_dispatch_request()
      File "/Users/Ricardo/Documents/python/openshift/scheduler_env/lib/python2.7/site-packages/flask/app.py", line 1477, in full_dispatch_request
        rv = self.handle_user_exception(e)
      File "/Users/Ricardo/Documents/python/openshift/scheduler_env/lib/python2.7/site-packages/flask_restful/__init__.py", line 263, in error_router
        return original_handler(e)
      File "/Users/Ricardo/Documents/python/openshift/scheduler_env/lib/python2.7/site-packages/flask/app.py", line 1381, in handle_user_exception
        reraise(exc_type, exc_value, tb)
      File "/Users/Ricardo/Documents/python/openshift/scheduler_env/lib/python2.7/site-packages/flask_restful/__init__.py", line 260, in error_router
        return self.handle_error(e)
      File "/Users/Ricardo/Documents/python/openshift/scheduler_env/lib/python2.7/site-packages/flask/app.py", line 1475, in full_dispatch_request
        rv = self.dispatch_request()
      File "/Users/Ricardo/Documents/python/openshift/scheduler_env/lib/python2.7/site-packages/flask/app.py", line 1461, in dispatch_request
        return self.view_functions[rule.endpoint](**req.view_args)
      File "/Users/Ricardo/Documents/python/openshift/scheduler_env/lib/python2.7/site-packages/flask_restful/__init__.py", line 431, in wrapper
        resp = resource(*args, **kwargs)
      File "/Users/Ricardo/Documents/python/openshift/scheduler_env/lib/python2.7/site-packages/flask_httpauth.py", line 60, in decorated
        return f(*args, **kwargs)
      File "/Users/Ricardo/Documents/python/openshift/scheduler_env/lib/python2.7/site-packages/flask/views.py", line 84, in view
        return self.dispatch_request(*args, **kwargs)
      File "/Users/Ricardo/Documents/python/openshift/scheduler_env/lib/python2.7/site-packages/flask_restful/__init__.py", line 521, in dispatch_request
        resp = meth(*args, **kwargs)
      File "/Users/Ricardo/Documents/python/openshift/scheduler_env/scheduler/ws/v1/schedulesapns.py", line 21, in get
        apns.send_message(tokens=['fad71c0b27416f055bfb1617c8db4e55d1b98b412443e68fba65cfe59748b81a'], alert='hi world', extra={})
      File "/Users/Ricardo/Documents/python/openshift/scheduler_env/scheduler/apns/__init__.py", line 134, in send_message
        res = srv.send(message)
      File "/Users/Ricardo/Documents/python/openshift/scheduler_env/lib/python2.7/site-packages/apnsclient/apns.py", line 90, in send
        status = self._connection.send(message)
      File "/Users/Ricardo/Documents/python/openshift/scheduler_env/lib/python2.7/site-packages/apnsclient/transport.py", line 255, in send
        with self:
      File "/Users/Ricardo/Documents/python/openshift/scheduler_env/lib/python2.7/site-packages/apnsclient/transport.py", line 228, in __enter__
        self._open_connection() # can raise exception, bubblit up to the top
      File "/Users/Ricardo/Documents/python/openshift/scheduler_env/lib/python2.7/site-packages/apnsclient/transport.py", line 519, in _open_connection
        timeout=self.session.connect_timeout
      File "/Users/Ricardo/Documents/python/openshift/scheduler_env/lib/python2.7/site-packages/apnsclient/backends/__init__.py", line 88, in get_cached_connection
        return self.get_new_connection(address, certificate, timeout=timeout)
      File "/Users/Ricardo/Documents/python/openshift/scheduler_env/lib/python2.7/site-packages/apnsclient/backends/stdio.py", line 378, in get_new_connection
        return self.connection_class(address, certificate, timeout=timeout)
      File "/Users/Ricardo/Documents/python/openshift/scheduler_env/lib/python2.7/site-packages/apnsclient/backends/stdio.py", line 142, in __init__
        self._open_connection(timeout)
      File "/Users/Ricardo/Documents/python/openshift/scheduler_env/lib/python2.7/site-packages/apnsclient/backends/stdio.py", line 153, in _open_connection
        self._connect_and_handshake()
      File "/Users/Ricardo/Documents/python/openshift/scheduler_env/lib/python2.7/site-packages/apnsclient/backends/stdio.py", line 188, in _connect_and_handshake
        self._connection.do_handshake()
      File "/Users/Ricardo/Documents/python/openshift/scheduler_env/lib/python2.7/site-packages/OpenSSL/SSL.py", line 1442, in do_handshake
        self._raise_ssl_error(self._ssl, result)
      File "/Users/Ricardo/Documents/python/openshift/scheduler_env/lib/python2.7/site-packages/OpenSSL/SSL.py", line 1180, in _raise_ssl_error
        raise SysCallError(-1, "Unexpected EOF")
    SysCallError: (-1, 'Unexpected EOF')

      

+3


source to share


1 answer


Finally, I corrected thanks for posting.

To enable logging:

import logging
logging.basicConfig()

      



To fix a bug WARNING:apnsclient.backends.stdio:Failed to establish socket/SSL connection to ('gateway.sandbox.push.apple.com', 2195)

caused by a security issue with SSL 3.0, Apple Notification Server is removing support for SSL 3.0 as of Wednesday October 29, 2014.

def my_callback(key, reason):
    print "my_callbaaaaaaack"
    print str(key)
    print str(reason)

import OpenSSL
OpenSSL.SSL.SSLv3_METHOD = OpenSSL.SSL.TLSv1_METHOD
from apns import APNS
apns = APNS(app, cert_file='ck.pem', passphrase='mypassphrase', failure_callback=my_callback)

      

+4


source







All Articles