Skip to content

Commit 09b1804

Browse files
authored
Merge pull request #59 from launchdarkly/dr/jsonPickle
More defensive json serialization for events
2 parents b9fc62a + b8fa377 commit 09b1804

File tree

4 files changed

+15
-4
lines changed

4 files changed

+15
-4
lines changed

CONTRIBUTING.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,3 +20,10 @@ Development information (for developing this module itself)
2020
1. Run tests: You'll need redis running locally on its default port of 6379.
2121

2222
$ py.test testing
23+
24+
Developing with different python versions
25+
-----------------------------------------
26+
27+
Example for switching to python 3:
28+
29+
```virtualenv -p `which python3` ~/.virtualenvs/python-client```

demo/demo.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
ch = logging.StreamHandler(sys.stdout)
1212
ch.setLevel(logging.DEBUG)
13-
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
13+
formatter = logging.Formatter('%(asctime)s - %(name)s:%(lineno)d - %(levelname)s - %(message)s')
1414
ch.setFormatter(formatter)
1515
root.addHandler(ch)
1616

ldclient/event_consumer.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
from __future__ import absolute_import
22

33
import errno
4-
import json
54
from threading import Thread
65

6+
import jsonpickle
77
import requests
88
from requests.packages.urllib3.exceptions import ProtocolError
99

@@ -42,12 +42,15 @@ def do_send(should_retry):
4242
body = [events]
4343
else:
4444
body = events
45+
46+
json_body = jsonpickle.encode(body, unpicklable=False)
47+
log.debug('Sending events payload: ' + json_body)
4548
hdrs = _headers(self.sdk_key)
4649
uri = self._config.events_uri
4750
r = self._session.post(uri,
4851
headers=hdrs,
4952
timeout=(self._config.connect_timeout, self._config.read_timeout),
50-
data=json.dumps(body))
53+
data=json_body)
5154
r.raise_for_status()
5255
except ProtocolError as e:
5356
inner = e.args[1]

requirements.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,5 @@ CacheControl>=0.10.2
22
requests>=2.10.0
33
sseclient>=0.0.12
44
future>=0.15.2
5-
strict-rfc3339>=0.7
5+
strict-rfc3339>=0.7
6+
jsonpickle==0.9.3

0 commit comments

Comments
 (0)