# Buggy code
def perform_ping(self, server):
    url = urljoin(server, "/api/v1/pingback")

    instance, _ = InstanceIDModel.get_or_create_current_instance()

    devicesettings = DeviceSettings.objects.first()
    language = devicesettings.language_id if devicesettings else ""

    try:
        timezone = get_current_timezone().zone
    except Exception:
        timezone = ""

    data = {
        "instance_id": instance.id,
        "version": kolibri.__version__,
        "mode": os.environ.get("KOLIBRI_RUN_MODE", ""),
        "platform": instance.platform,
        "sysversion": instance.sysversion,
        "database_id": instance.database.id,
        "system_id": instance.system_id,
        "node_id": instance.node_id,
        "language": language,
        "timezone": timezone,
        "uptime": int((datetime.now() - self.started).total_seconds() / 60),
    }

    logger.debug("Pingback 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_ping(self, server):
    url = urljoin(server, "/api/v1/pingback")

    instance, _ = InstanceIDModel.get_or_create_current_instance()

    devicesettings = DeviceSettings.objects.first()
    language = devicesettings.language_id if devicesettings else ""

    try:
        timezone = get_current_timezone().zone
    except Exception:
        timezone = ""

    data = {
        "instance_id": instance.id,
        "version": kolibri.__version__,
        "mode": os.environ.get("KOLIBRI_RUN_MODE", ""),
        "platform": instance.platform,
        "sysversion": instance.sysversion,
        "database_id": instance.database.id,
        "system_id": instance.system_id,
        "node_id": instance.node_id,
        "language": language,
        "timezone": timezone,
        "uptime": int((datetime.now() - self.started).total_seconds() / 60),
    }

    logger.debug("Pingback 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 "{}")