# Buggy code
def periodic_read(self):
    _log.debug("scraping device: " + self.device_name)

    try:
        results = self.interface.scrape_all()
    except Exception as ex:
        _log.exception(ex)
        return

    # XXX: Does a warning need to be printed?
    if not results:
        return

    now = datetime.datetime.utcnow().isoformat(" ") + "Z"

    headers = {
        headers_mod.DATE: now,
    }

    for point, value in results.iteritems():
        topics = self.get_paths_for_point(point)
        for topic in topics:
            message = [value, self.meta_data[point]]
            self.vip.pubsub.publish("pubsub", topic, headers=headers, message=message)

    message = [results, self.meta_data]
    self.vip.pubsub.publish(
        "pubsub", self.all_path_depth, headers=headers, message=message
    )

    self.vip.pubsub.publish(
        "pubsub", self.all_path_breadth, headers=headers, message=message
    )


# Traceback (TypeError)
2015-08-28 08:38:59,118 (forwarderagent-3.0 6934) volttron.platform.agent.base_historian ERROR: An unhandled exception has occured while publishing to historian.
2015-08-28 08:38:59,119 (forwarderagent-3.0 6934) <stderr> ERROR: Traceback (most recent call last):
2015-08-28 08:38:59,119 (forwarderagent-3.0 6934) <stderr> ERROR:   File "/usr/lib/python2.7/logging/__init__.py", line 851, in emit
2015-08-28 08:38:59,120 (forwarderagent-3.0 6934) <stderr> ERROR:     msg = self.format(record)
2015-08-28 08:38:59,120 (forwarderagent-3.0 6934) <stderr> ERROR:   File "/usr/lib/python2.7/logging/__init__.py", line 724, in format
2015-08-28 08:38:59,120 (forwarderagent-3.0 6934) <stderr> ERROR:     return fmt.format(record)
2015-08-28 08:38:59,120 (forwarderagent-3.0 6934) <stderr> ERROR:   File "/home/volttron/volttron-3x/volttron/platform/agent/utils.py", line 228, in format
2015-08-28 08:38:59,121 (forwarderagent-3.0 6934) <stderr> ERROR:     return jsonapi.dumps(dct)
2015-08-28 08:38:59,121 (forwarderagent-3.0 6934) <stderr> ERROR:   File "/home/volttron/volttron-3x/env/local/lib/python2.7/site-packages/zmq/utils/jsonapi.py", line 40, in dumps
2015-08-28 08:38:59,121 (forwarderagent-3.0 6934) <stderr> ERROR:     s = jsonmod.dumps(o, **kwargs)
2015-08-28 08:38:59,122 (forwarderagent-3.0 6934) <stderr> ERROR:   File "/home/volttron/volttron-3x/env/local/lib/python2.7/site-packages/simplejson/__init__.py", line 397, in dumps
2015-08-28 08:38:59,122 (forwarderagent-3.0 6934) <stderr> ERROR:     **kw).encode(obj)
2015-08-28 08:38:59,122 (forwarderagent-3.0 6934) <stderr> ERROR:   File "/home/volttron/volttron-3x/env/local/lib/python2.7/site-packages/simplejson/encoder.py", line 275, in encode
2015-08-28 08:38:59,122 (forwarderagent-3.0 6934) <stderr> ERROR:     chunks = self.iterencode(o, _one_shot=True)
2015-08-28 08:38:59,123 (forwarderagent-3.0 6934) <stderr> ERROR:   File "/home/volttron/volttron-3x/env/local/lib/python2.7/site-packages/simplejson/encoder.py", line 357, in iterencode
2015-08-28 08:38:59,123 (forwarderagent-3.0 6934) <stderr> ERROR:     return _iterencode(o, 0)
2015-08-28 08:38:59,123 (forwarderagent-3.0 6934) <stderr> ERROR:   File "/home/volttron/volttron-3x/env/local/lib/python2.7/site-packages/simplejson/encoder.py", line 252, in default
2015-08-28 08:38:59,124 (forwarderagent-3.0 6934) <stderr> ERROR:     raise TypeError(repr(o) + " is not JSON serializable")
2015-08-28 08:38:59,124 (forwarderagent-3.0 6934) <stderr> ERROR: TypeError: ProtocolError('previous send operation is not complete',) is not JSON serializable
2015-08-28 08:38:59,124 (forwarderagent-3.0 6934) <stderr> ERROR: Logged from file base_historian.py, line 370

# Fixed code
def periodic_read(self):
    _log.debug("scraping device: " + self.device_name)

    try:
        results = self.interface.scrape_all()
    except Exception:
        _log.exception("unhandled exception")
        return

    # XXX: Does a warning need to be printed?
    if not results:
        return

    now = datetime.datetime.utcnow().isoformat(" ") + "Z"

    headers = {
        headers_mod.DATE: now,
    }

    for point, value in results.iteritems():
        topics = self.get_paths_for_point(point)
        for topic in topics:
            message = [value, self.meta_data[point]]
            self.vip.pubsub.publish("pubsub", topic, headers=headers, message=message)

    message = [results, self.meta_data]
    self.vip.pubsub.publish(
        "pubsub", self.all_path_depth, headers=headers, message=message
    )

    self.vip.pubsub.publish(
        "pubsub", self.all_path_breadth, headers=headers, message=message
    )