djacobs / PyAPNs

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

Using frame and enhanced #90

Closed xhijack closed 9 years ago

xhijack commented 9 years ago

Hi, I tried to use enhanced with frame (multiple token).

File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 808, in bootstrap_inner self.run() File "/System/Library/Frameworks/Python.framework/Versions/2.7/lib/python2.7/threading.py", line 761, in run self.__target(_self.args, *_self.__kwargs) File "/Users/appsfoundry/sites/flask/scooprms/ENV/lib/python2.7/site-packages/apns.py", line 564, in _read_error_response self._resend_notifications_by_id(identifier) File "/Users/appsfoundry/sites/flask/scooprms/ENV/lib/python2.7/site-packages/apns.py", line 567, in _resend_notifications_by_id fail_idx = Util.getListIndexFromID(self._sent_notifications, failed_identifier) File "/Users/appsfoundry/sites/flask/scooprms/ENV/lib/python2.7/site-packages/apns.py", line 589, in getListIndexFromID return next(index for (index, d) in enumerate(the_list) StopIteration

xilvar commented 9 years ago

I've been having the same problem. It looks like this is because:

def send_notification_multiple(self, frame): return self.write(frame.get_frame())

does not do what send_notification does:

self._sent_notifications.append(dict({'id': identifier, 'message': message}))

So _sent_notifications is empty when the worker thread tries to get the remaining notifications.

xilvar commented 9 years ago

I created a pull request which seems to fix this problem : https://github.com/djacobs/PyAPNs/pull/92

xhijack commented 9 years ago

Have you tested it? I've tested it and it didn't show any error. but my notif isn't sent

xilvar commented 9 years ago

To see errors you need to register a response_listener before you send. For example:

def response_listener(error_response): print error_response apns_connection_sandbox.gateway_server.register_response_listener(response_listener)

I believe the intended behavior of the enhanced frames is to basically follow this pattern:

  1. Make a frame of 10 notifications.
  2. Send the frame through the connection
  3. On the second thread, listen for errors.
  4. If errors occur, then every notification in the frame in question AFTER the error notification was also dropped
  5. The library reports back the error status and the identifier of the frame.
  6. The library tries then to re-send all notifications AFTER the error frame.
  7. The library then goes back to listening for errors.

So basically the intention appears to be that it tells you which notifications are bad and why (status code), and helps you to retry the notifications which were dropped due to the bad one.

I'm guessing that your apns token is bad or your key/cert is bad.