Skip to content

Commit

Permalink
Fix crash when sending UTF-8 characters.
Browse files Browse the repository at this point in the history
The `ensure_ascii` kwarg in `json.dumps()` must be `True` (the
default) so that the subsequent UTF-8 encoding works correctly.
  • Loading branch information
jwatson committed Sep 5, 2013
1 parent bf7cecf commit f4c2051
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions pyapns/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,8 @@ def binaryify(t):
'token "{}" could not be decoded: {}'.format(str(t), str(e)
))

encoded_payload = json.dumps(self.payload, separators=(',', ':'),
ensure_ascii=False).encode('utf-8')
encoded_payload = json.dumps(self.payload,
separators=(',', ':')).encode('utf-8')
return structify(binaryify(self.token), self.internal_identifier,
self.expiry, encoded_payload)

Expand Down

1 comment on commit f4c2051

@jjyao
Copy link

@jjyao jjyao commented on f4c2051 Apr 1, 2014

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Previous code is correct. Why does it crash? Do you use ujson?

Please sign in to comment.