Export to GitHub

apns-python-wrapper - issue #7

Still doesn't handle unicode strings


Posted on Jul 7, 2010 by Quick Panda

Steps to reproduce: >>> import APNSWrapper >>> a = APNSWrapper.APNSNotification() >>> a.alert(u"BLAHBLAHBLAH") <APNSWrapper.notifications.APNSNotification object at 0x426c70> >>> a.badge(4) >>> a.tokenHex(<YOUR_KEY_HERE>) <APNSWrapper.notifications.APNSNotification object at 0x426c70> >>> b = APNSWrapper.APNSNotificationWrapper(certificate=<PATH_TO_YOUR_FILE>, sandbox=True) >>> b.append(a) >>> b.notify() True

The device will set the badge correctly (to 4) but it won't show any alert message. This is because there is no alert message sent, since it's unicode.

I've included a patch below.

--- a/APNSWrapper/notifications.py Wed May 19 21:41:49 2010 +0300 +++ b/APNSWrapper/notifications.py Wed Jul 07 11:50:51 2010 -0400 @@ -324,6 +324,9 @@ if isinstance(self.alertObject, str): alertArgument = _doublequote(self.alertObject) apsKeys.append('"alert":"%s"' % alertArgument) + elif isinstance(self.alertObject, unicode): + alertArgument = _doublequote(self.alertObject.encode("utf-8")) + apsKeys.append('"alert":"%s"' % alertArgument) elif isinstance(self.alertObject, APNSAlert): alertArgument = self.alertObject._build() apsKeys.append('"alert":{%s}' % alertArgument)

Comment #1

Posted on Jul 8, 2010 by Swift Rabbit

APNSProperty does not also handle unicode as the data.

if not isinstance(data, (int, str, list, tuple, float)): should be: if not isinstance(data, (int, str, list, tuple, float, unicode)):

Comment #2

Posted on Jul 7, 2011 by Happy Elephant

I also run into this issue and had to encode the msg in UTF-8 before pushing it : msg.encode("utf-8")

Morever, I'm having issue trying to push the '\n' char in a message like "This is a \n test". Did anybody manage to achieve that ? :/

Comment #3

Posted on Jul 14, 2011 by Happy Cat

I working on it these days so there's a lot of changes is coming - so please, be patient, I will release new version if few days

Comment #4

Posted on Sep 21, 2012 by Happy Dog

This bombs: alert.loc_args([u"Márcio"])

I had to patch line 73 of notifications.py to look like this:

self.locArgs = [ '"%s"'.encode('utf8') % x.encode('utf8') for x in la ]

Comment #5

Posted on Sep 21, 2012 by Happy Dog

Make that

 self.locArgs = [ '"%s"'.encode('utf8') % unicode(x).encode('utf8') for x in la ]

(so that it can eat any values, like teh original code).

Status: New

Labels:
Type-Defect Priority-Medium