djacobs / PyAPNs

Python library for interacting with the Apple Push Notification service (APNs)
http://pypi.python.org/pypi/apns/
MIT License
1.22k stars 377 forks source link

Exception: [Errno 8] _ssl.c:510: EOF occurred in violation of protocol #133

Closed Vkt0r closed 7 years ago

Vkt0r commented 8 years ago

I'm running the package in a Django app in Ubuntu 14.04 and when I try to sent the notification to several devices I get in my log file the message :

Exception: [Errno 8] _ssl.c:510: EOF occurred in violation of protocol

This is the code I using :

class NotificationSystem:

    def __init__(self):
        """
        Init the class with the APNS client using the library APNs.

        """
        self.apns_client = APNs(use_sandbox=settings.SANDBOX, cert_file=cert_filename, key_file=key_filename)

    def __send_notification(self, token_ex, payload_ex):
        """
        Send the notification to the specified token with the specified payload.
        :param token_ex: The token to send the message.
        :param payload_ex: The payload to send.
        """
        self.apns_client.gateway_server.send_notification(token_ex, payload_ex, identifier=None,
                                                      expiry=(datetime.utcnow() + timedelta(300)))

    def send_multiples_notifications(self, tokens, payload, delay):
        """
        Send multiples notifications to several devices.
        :param tokens: The tokens to use to send to the devices.
        :param payload: The payload to send to the devices.
        :param delay: The delay to wait among notifications.
        """

        logger.info("Notification received at %s" % (time.ctime(time.time())))

        # wait a delay to send the notification to the devices.
        time.sleep(delay)

        for row in tokens:
            try:
                self.__send_notification(row.token, payload)
                logger.info("Notification sent to token %s %s" % (str(row.token), time.ctime(time.time())))
            except Exception, e:
                logger.info("Exception: %s" % (str(e)))
                logger.info("Token: %s" % row.token)

In develop(with use_sandbox=True and the respective certificates ) mode it works fine, but when I try to go in production with the Django deployment using WSGI it keep saying the above error.

Any help is well received.

ghost commented 8 years ago

Same error here, but I'm using sandbox mode.

gensmusic commented 8 years ago

same error here. when test on my local machine it's ok. But error occurs when deploy to server using UWSGI

Vkt0r commented 8 years ago

In my case I fix the error regarding the use of threads in my server to run the APNS Server

damozhang commented 8 years ago

Same error here.

lexaf commented 8 years ago

Same error here.

pawelnowak commented 8 years ago

A little odd solution, but in my case it helped to export the p12 certificate with some other passphrase.