Skip to content

Commit d1bc913

Browse files
committed
specify json return
1 parent 1118132 commit d1bc913

File tree

2 files changed

+6
-4
lines changed

2 files changed

+6
-4
lines changed

posthog/client.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,12 +33,14 @@ def __init__(self, api_key=None, host=None, debug=False,
3333
max_queue_size=10000, send=True, on_error=None, flush_at=100,
3434
flush_interval=0.5, gzip=False, max_retries=3,
3535
sync_mode=False, timeout=15, thread=1, poll_interval=30, personal_api_key=None, project_api_key=None):
36-
require('api_key', api_key, string_types)
3736

3837
self.queue = queue.Queue(max_queue_size)
3938

4039
# api_key: This should be the Team API Key (token), public
4140
self.api_key = api_key or project_api_key
41+
42+
require('api_key', self.api_key, string_types)
43+
4244
self.on_error = on_error
4345
self.debug = debug
4446
self.send = send

posthog/request.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,13 @@ def post(api_key, host=None, path=None, gzip=False, timeout=15, **kwargs):
4646
return res
4747

4848

49-
def _process_response(res, success_message):
49+
def _process_response(res, success_message, return_json=True):
5050
log = logging.getLogger('posthog')
5151
if not res:
5252
raise APIError('N/A', 'Error when fetching PostHog API, please make sure you are using your public project token/key and not a private API key.')
5353
if res.status_code == 200:
5454
log.debug(success_message)
55-
return res.json()
55+
return res.json() if return_json else res
5656
try:
5757
payload = res.json()
5858
log.debug('received response: %s', payload)
@@ -69,7 +69,7 @@ def decide(api_key, host=None, gzip=False, timeout=15, **kwargs):
6969
def batch_post(api_key, host=None, gzip=False, timeout=15, **kwargs):
7070
"""Post the `kwargs` to the batch API endpoint for events"""
7171
res = post(api_key, host, '/batch/', gzip, timeout, **kwargs)
72-
return _process_response(res, success_message='data uploaded successfully')
72+
return _process_response(res, success_message='data uploaded successfully', return_json=False)
7373

7474

7575
def get(api_key, url, host=None, timeout=None):

0 commit comments

Comments
 (0)