Skip to content

Commit

Permalink
Merge pull request #61 from mehmetminanc/encoding-fix
Browse files Browse the repository at this point in the history
Some encoding fixes
  • Loading branch information
marcel corso gonzalez authored Jun 28, 2021
2 parents 92ce5cc + bd995a4 commit 5f4d9ae
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
2 changes: 1 addition & 1 deletion messagebird/http_client.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ def request(self, path, method='GET', params=None, format=ResponseFormat.text):
'Accept': 'application/json',
'Authorization': 'AccessKey ' + self.access_key,
'User-Agent': self.user_agent,
'Content-Type': 'application/json'
'Content-Type': 'application/json; charset=UTF-8'
}

method_switcher = {
Expand Down
4 changes: 2 additions & 2 deletions messagebird/serde.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@

def json_serialize(obj):
try:
return json.dumps(obj)
return json.dumps(obj, ensure_ascii=False).encode('utf-8')
except TypeError:
return json.dumps(obj, default=lambda o: o.__dict__)
return json.dumps(obj, default=lambda o: o.__dict__, ensure_ascii=False).encode('utf-8')
15 changes: 15 additions & 0 deletions tests/test_serde.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# coding=utf-8
import unittest

from messagebird.serde import json_serialize


class TestJSONSerDe(unittest.TestCase):

def test_tr_check(self):
self.assertEqual(json_serialize({'body': 'Pijamalı hasta, yağız şoföre çabucak güvendi.'}),
"""{"body": "Pijamalı hasta, yağız şoföre çabucak güvendi."}""".encode("utf-8"))

def test_jp_check(self):
self.assertEqual(json_serialize({'body': 'いろはにほへとちりぬるを'}),
"""{"body": "いろはにほへとちりぬるを"}""".encode("utf-8"))

0 comments on commit 5f4d9ae

Please sign in to comment.