# Buggy code
def perform_statistics(self, server, pingback_id):
    url = urljoin(server, "/api/v1/statistics")

    channels = [extract_channel_statistics(c) for c in ChannelMetadata.objects.all()]
    facilities = [extract_facility_statistics(f) for f in Facility.objects.all()]

    data = {
        "pi": pingback_id,
        "c": channels,
        "f": facilities,
    }

    logger.debug("Statistics data: {}".format(data))

    jsondata = dump_zipped_json(data)

    response = requests.post(url, data=jsondata, timeout=60)

    response.raise_for_status()

    return json.loads(response.content or "{}")


# Traceback (TypeError)
INFO:kolibri.core.analytics.management.commands.ping:Ping succeeded! (response: {'id': 87135})
Exception in thread Thread-1:
Traceback (most recent call last):
File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/threading.py", line 916, in _bootstrap_inner
self.run()
File "/Users/d/Projects/learning_equality/repos/k011x/kolibri/utils/server.py", line 109, in run
call_command("ping")
File "/Users/d/Projects/learning_equality/repos/k011x/.venv/lib/python3.6/site-packages/django/core/management/__init__.py", line 131, in call_command
return command.execute(*args, **defaults)
File "/Users/d/Projects/learning_equality/repos/k011x/.venv/lib/python3.6/site-packages/django/core/management/base.py", line 330, in execute
output = self.handle(*args, **options)
File "/Users/d/Projects/learning_equality/repos/k011x/kolibri/core/analytics/management/commands/ping.py", line 58, in handle
self.perform_statistics(server, data["id"])
File "/Users/d/Projects/learning_equality/repos/k011x/kolibri/core/analytics/management/commands/ping.py", line 123, in perform_statistics
jsondata = dump_zipped_json(data)
File "/Users/d/Projects/learning_equality/repos/k011x/kolibri/core/analytics/utils.py", line 37, in dump_zipped_json
jsondata = json.dumps(data)
File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/json/__init__.py", line 231, in dumps
return _default_encoder.encode(obj)
File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/json/encoder.py", line 199, in encode
chunks = self.iterencode(o, _one_shot=True)
File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/json/encoder.py", line 257, in iterencode
return _iterencode(o, 0)
File "/usr/local/Cellar/python/3.6.5/Frameworks/Python.framework/Versions/3.6/lib/python3.6/json/encoder.py", line 180, in default
o.__class__.__name__)
TypeError: Object of type 'bytes' is not JSON serializable

# Fixed code
def perform_statistics(self, server, pingback_id):
    url = urljoin(server, "/api/v1/statistics")

    channels = [extract_channel_statistics(c) for c in ChannelMetadata.objects.all()]
    facilities = [extract_facility_statistics(f) for f in Facility.objects.all()]

    data = {
        "pi": pingback_id,
        "c": channels,
        "f": facilities,
    }

    logger.debug("Statistics data: {}".format(data))

    jsondata = dump_zipped_json(data)

    response = requests.post(url, data=jsondata, timeout=60)

    response.raise_for_status()

    return json.loads(response.content.decode() or "{}")